I'm doing an assignment for class it's a simple thing basically it's a window where you put in the RGB values to color the window and put two numbers (in the same first two fields) to set the window size. My problem is that my resize works when I put in values smaller than the default which I set to setSize(500,200). My second problem is that the window doesn't resize all the way. Only the area which is seen becomes smaller any ideas?
public void actionPerformed (ActionEvent bert)
{
if (bert.getSource()==b1)
{
num1 = Integer.parseInt(n1.getText());
num2 = Integer.parseInt(n2.getText());
num3 = Integer.parseInt(n3.getText());
Color c = new Color (num1, num2, num3);
p.setBackground(c);
}
if (bert.getSource()==b2)
{
num1 = Integer.parseInt(n1.getText());
num2 = Integer.parseInt(n2.getText());
p.setSize(num1,num2);
//p.setSize(100, 200);
}
if (bert.getSource()==b3)
{
Y m = new Y();
this line of code p.setSize(num1,num2);
needs rework.
See you are changeing the size of JPanel where as JPanel is part of the container, which is part of a JFrame.
The solution is to change the size of the JFrame....
thanks that worked perfectly, I appreciate it. Another question, the third part of this application is supposed to create a new instance of the window hence the name of the button "spawn". I was thinking that I have to create a new instance of the class but it creates a new window that's blank and it kinda freezes the screen. here's the part of my code which is for the spawn button:
if (bert.getSource()==b3)
{
Y m = new Y();
m.setSize(500,200);
m.setVisible(true);
MyInput.readString();
m.pack();
}
Bookmarks