Results 1 to 3 of 3
Thread: I need help about swing...
- 03-31-2012, 02:01 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
I need help about swing...
I have a homework from javaswing... I have from awt an example but l must return it to javaswing but I dont know how l can do it... thanks for help...
---------------------------------
import java.awt.*;
import java.awt.event.*;
public class menuawt {
static int w=300,h=250;
static Frame f;
public static void main(String [] args) {
f = new Frame("Frame 1");
Menu m = new Menu("Menu 1");
Button b = new Button("inc 10%"),
b2 = new Button("dec 10%");
MenuItem mi1 = new MenuItem("Increment 10%");
MenuItem mi2 = new MenuItem("Decrement 10%");
m.add(mi1);
m.add(mi2);
mi1.addActionListener(new Inc());
mi2.addActionListener(new Dec());
MenuBar mb = new MenuBar();
mb.add(m);
f.setLayout(new FlowLayout());
f.add(b);
f.add(b2);
b.addActionListener(new Inc());
b2.addActionListener(new Dec());
f.setSize(w, h);
f.setMenuBar(mb);
f.addWindowListener(new WL());
f.setVisible(true);
}
static class WL extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
static class Inc implements ActionListener{
public void actionPerformed(ActionEvent e) {
w+=w/10;
h+=h/10;
f.setSize(w, h);
}
}
static class Dec implements ActionListener{
public void actionPerformed(ActionEvent e) {
w-=w/10;
h-=h/10;
f.setSize(w, h);
}
}
}
- 03-31-2012, 02:46 PM #2
Re: I need help about swing...
Many Swing classes that provide the same features as an AWT class have the same name with a leading J. For example Frame and JFrame.
For a first pass on converting the code, read the API doc to see if the AWT class that is being used has a Swing class.
You will need to add import statements for the Swing classes that you use.
Please edit your code and add proper indentation for each nesting level within a pair of {}s.
The code should NOT all start in the first column.If you don't understand my response, don't ignore it, ask a question.
-
Re: I need help about swing...
You shouldn't borrow code and try to use it or worse, ask others to translate it to Swing for you without showing any of your own work. The way to solve your problem is by learning from the Swing tutorials and then using this information to create the class yourself. If you get stuck, please don't simply dump your work here, but rather show what you've done, ask an intelligent question, and we'll likely be more than happy to try to help you.
Similar Threads
-
Swing To Jsp
By jim in forum Advanced JavaReplies: 1Last Post: 10-09-2011, 11:51 PM -
About Swing
By satimis in forum New To JavaReplies: 2Last Post: 05-01-2010, 05:37 PM -
What is next to Swing
By javaplus in forum AWT / SwingReplies: 1Last Post: 01-13-2008, 10:16 PM -
where is the swing jar?
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:58 PM -
map javax.swing.text.Element to javax.swing.text.View
By elizabeth in forum New To JavaReplies: 1Last Post: 07-30-2007, 07:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks