Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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!!
If you don't understand my answer, don't ignore it, ask a question.
Are you seriously just dumping your homework here? That's pretty rude...
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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?
If you don't understand my answer, don't ignore it, ask a question.
please refer my attachment on below!
11.jpg
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
If you don't understand my answer, don't ignore it, ask a question.
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?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.
If you don't understand my answer, don't ignore it, ask a question.
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?
If you don't understand my answer, don't ignore it, ask a question.