i have some confuse this dew question!can you let me know how to solution this few question!thank you!!!pls refer the attachment!
Attachment 1179Attachment 1180
Printable View
i have some confuse this dew question!can you let me know how to solution this few question!thank you!!!pls refer the attachment!
Attachment 1179Attachment 1180
Please post the full text of the questions (not an image!!!) and your answers for all of them or what your ideas are about each question so we can help you understand.
Is this the same question:
need help for the few question for java program!!
Are you seriously just dumping your homework here? That's pretty rude...
for q4!my program on below,cab you let me know why i click the button,why can not change the size?please help!!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class tma2 {
public static void main(String[] args) {
JFrame jj=new JFrame("adjust");
int size=200;
JButton big=new JButton("BIG");
JButton small=new JButton("SMALL");
big.addActionListener(new ActionListener(){
protected int i=1;
public void actionPerformed(ActionEvent e)
{
System.out.println(i++);
}
});
small.addActionListener(new ActionListener(){
protected int j=20;
public void actionPerformed(ActionEvent e)
{
System.out.println(j++);
}
});
jj.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
});
jj.getContentPane().add(big,"North");
jj.getContentPane().add(small,"South");
jj.setSize(size,size);
jj.setVisible(true);
}
}
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting. Your formatting makes it very to hard and understand your code.
Where do you try to change the size?
please refer my attachment on below!
Attachment 1183
Please post what we need to see here on the forum.
You can not copy and paste from an image.
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
Code :import javax.swing.*; import java.awt.event.*; import java.awt.*; public class jframe { public static void main(String[] args) { JFrame jj=new JFrame("adjust"); int i=200; JButton big=new JButton("BIG"); JButton small=new JButton("SMALL"); big.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.out.println(i++); } }); small.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { System.out.println(i--); } }); jj.addWindowListener(new WindowAdapter() { public void WindowClosing(WindowEvent e) { System.exit(0); } }); jj.getContentPane().add(big,"North"); jj.getContentPane().add(small,"South"); jj.setSize(i,i); jj.setVisible(true); } }
Where do you try to change the size of anything?Quote:
i click the button,why can not change the size
I see that the value of the variable: i is changed in the button listeners.
for part a
You can change the size of a JFrame by using the setSize(int h, int v) method,where h and v give the horizontal and vertical dimensions of the applet’s window in pixels. Write a GUI application that contains two JButtons, labeled “Big” and “Small.” Whenever the user clicks on Small, set the applets dimensions to 200 x100, and whenever the user clicks on Big, set the dimensions to 300 x 200.
for part b
Rewrite your solution to the previous exercise so that it uses a single button, whose label is toggled appropriately each time it is clicked. Obviously, when the JButtonis labeled “Big,” clicking it should give the applet its big dimensions.
Is that the answer to my question? I don't see how it does.
How does the posted code change the size of anything?