Drawing Simple Yellow Rectangle In White Background?
Feb 1, 2014
Here is the code, I just wanted to draw a simple yellow rectangle in white background...
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends Jframe {
Rectangle test = new Rectangle(100,100,100,100);
public NewEmpty()
[Code] .....
Errors in the compiler ( i think there's something wrong with that Jframe)
init:
deps-jar:
Compiling 1 source file to C:Users****Gametestbuildclasses
C:UsersMarcoGametestsrcgametestNewEmpty.java :6: error: cannot find symbol
public class NewEmpty extends Jframe {
If I "embed" a ProgressIndicator inside a ListView it has an ugly border and a white background. It looks like there's a TextField below the ProgressIndicator.
Why does it behave like that and how to solve it so that the progress indicator is transparent.
I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...
import javax.swing.*; import java.util.*; import java.awt.*; public class HomePage { JFrame frame; JPanel pnl1, pnl2, pnl3; JLabel lbl;
I'm currently making a Breakout clone to learn about different ways of organizing my code and whatnot but I've run into a problem with the positioning of some pieces versus the position of the mouse.
I've created a blue rectangle on the screen that turns white when the mouse hovers over it, BUT it actually only ends up turning white about halfway down and then continues on off the block. I moved the rectangle to 0,0 to see where it draws and it looks like it is drawing to the very top left corner of the window itself but for the mouse coordinates, the top left is just where the black area is and excludes the borders of the window.
Here is the class rendering the rectangle, it extends from a class that in turn extends from the JPanel class:
public class MainMenuState extends MenuState { JFrame gameFrame; Graphics2D g; // PlayButton variables int playPosX = 0; int playPosY = 0; int playWidth = 100; int playHeight = 50;
[Code] ....
A few other things I tried that I can think off the top of my head: Play around with different layouts (at times this caused the screen to shrink to a small size as well as using pack()), using setSize() setLocation() or setBorder() in the MainMenuState class which had no effect.
Someone on another forum also suggested trying to utilize component.getLocationOnScreen(): I tried two things with the getXOnScreen method, first subtracting with the location of the JPanel which of course gave me the same problem. After that I tried
I've just started working on a program and I'm already having difficulties with the program. I can't get the background color to change from the basic gray color.
Java Code:
import javax.swing.JFrame; import javax.swing.WindowConstants; import java.awt.*; import java.lang.Object; import java.awt.Color; public class FrameDemo{
Ok. So I have decided that taking a step back is better than trying to go forward blind. I am trying to come to an understanding of how java draws simple shapes, but continue to run into problems. I have now gone ahead and directly copied code from a book just to see if it will work. It does not. The code is just supposed to make a smiley face, but when I run it I get a bunch of errors. I have attached the code that I am trying to run and the error report at the bottom.
Java Code:
import javax.swing.JFrame; public class DrawSmileyTest { public static void main( String[] args ); DrawSmiley panel = new DrawSmiley(); JFrame application = new JFrame(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add( panel );
import javax.swing.*; import java.awt.*; public class PRJ04 extends JFrame { public static void main (String [] args) { PRJ04 frmApp = new PRJ04(); PanelChart pnlChart = new PanelChart();
[Code] .....
When I comment out the adding and setting of the pnlChart on my main driver, the pnlPopulationInputs shows up fine, and it runs ok. When I add the pnlChart I get errors like crazy and a white screen. My errors:
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero at PanelChart.drawChart(PanelChart.java:45) at PanelChart.paintComponent(PanelChart.java:24) at javax.swing.JComponent.paint(JComponent.java:1054)
[Code] ....
Once more with this one, I refer back to our in class example. Our programs are set up the same, yet he has no issues with the "/ by zero" exception.
What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.
Java Code:
public ImageIcon getBackImage(){ before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB); int w = before.getWidth(); int h = before.getHeight(); try{ URL url = getClass().getResource("/Blue_Back.png"); before = ImageIO.read(url);
[Code] ......
The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
When I open applications specially high graphics applications, the screen flashes with whole black display with a number of horizontal white lines then after 2 or 3 flashes it opens the desired program. What is the cause, is it low graphics memory, physically damaged screen or ?
I'm stuck with a problem. The code below generates a coloured image.
//Setting the size of the graphics window final int WINDOW_DIMENSION = 200; final int SIZE_FACTOR = 3; EasyGraphics generate = new EasyGraphics(WINDOW_DIMENSION*SIZE_FACTOR,WINDOW_DIMENSION*SIZE_FACTOR);
//Constructing the arrays char[][] firstArray = new char[WINDOW_DIMENSION][WINDOW_DIMENSION]; char[] secondArray = scan.toCharArray();
[Code] ...
What I would like to do is generate a picture which is mostly white but the colour boundaries of the original picture are in black. I tried using the code below but it doesn't produce what I wanted.
for (int a = 1; a < WINDOW_DIMENSION; a++) { for (int b = 1; b < WINDOW_DIMENSION; b++) { generate.setColor(0,0,0); if(firstArray[a][b]!=firstArray[a-1][b] || firstArray[a][b]!=firstArray[a][b-1]) generate.setColor(255,255,255); generate.plot(a,b); } }
I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.
if(!writeSuccess) { //display output messages in JOptionPane JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE); //close the form me.dispose(); }
If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?
Thats my code, and the rectangle (ObstacleX is the X cordinate for the rectangle) goes fine on the first few times across the screen, then starts to go hyperspeed....
I have to do the following: A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane. Write a method that returns a bounding rectangle for a set of points in a two-dimensional plane, as follows:
public static MyRectangle2D getRectangle(double[][] points)
The Rectangle2D class is defined in Programming Exercise 10.13. Write a test program that prompts the user to enter five points and displays the bounding rectangle's center, width, and height. Here is a sample run:
Enter five points: 1.0 2.5 3 4 5 6 7 8 9 10.The bounding rectangle's center (5.0, 6.25), width 8.0, height 7.5
This is my code so far, taking in account that Rectangle2D is already done in a previous problem.the thing is that i don't know if i have to erase public static void or do i leave it or how do i start it?
package theboundingrectangle; import java.util.Scanner; public static MyRectangle2D getRectangle(double[][] points) public class TheBoundingRectangle { public static void main(String[] args) { // TODO code application logic here } }
in order to speed up my application I want 'paintComponent(Graphics g)' to only write the visible area in my viewport. I can not find how to get that Rectangle from my JScrollPane.
So I've been getting back into Java and downloaded eclipse back onto my laptop. However when I go to make a simple rectangle into a JFrame, the frame will pop up but no rectangle will be shown. Here is my main class, which sets up the JFrame...
mport javax.swing.JFrame; public class Frame{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("I hope this fucking works"); frame.setSize(400,400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Is there a way to simply slap a rectangle into a JPanel (make it appear) with out creating an inner Class or helper Method, all within "Main"? And if not, why?
Making a JFrame is easy.
Adding a JPanel is a snap.
import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class TheJFrame { public static void main(String[] args) { // TODO Auto-generated method stub
MyGraphics worked before I added a background but, even now when I take the background away it isn't showing up.
package com.snow.game; import javax.swing.*; import java.awt.*; class MyGraphics extends JComponent { //creating a class for graphics public void draw(Graphics g){ //calling Graphics making a new graphics (g) now you can use it to make objects g.drawRect(10, 10, 50, 50); //Draws a rectangle
I was tasked with building a program that, when is given a string by the user, takes it and prints it out as a rectangle. For example, if the user types in "COMPUTER", the output would be:
So, it works once, but then it doesn't work again. Here is my code:
i was tasked with building a program that, when is given a string by the user, takes it and prints it out as a rectangle. For example, if the user types in "COMPUTER", the output would be:
So, it works once, but then it doesn't work again. Here is my code:
import java.util.Scanner; public class WordRectangle { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner userInput = new Scanner (System.in);
So I also am working on this problem. My frame does print each new rectangle; however, it is printed each time from the top left corner, and the bottom right is where I click.
Here is my RectangleComponent:
import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.Shape; import java.util.ArrayList; import javax.swing.JComponent; public class RectangleComponent extends JComponent