Results 1 to 3 of 3
  1. #1
    CANN1 is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Unhappy 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);
    }
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default 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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I need help about swing...

    Quote Originally Posted by CANN1 View Post
    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...
    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

  1. Swing To Jsp
    By jim in forum Advanced Java
    Replies: 1
    Last Post: 10-09-2011, 11:51 PM
  2. About Swing
    By satimis in forum New To Java
    Replies: 2
    Last Post: 05-01-2010, 05:37 PM
  3. What is next to Swing
    By javaplus in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2008, 10:16 PM
  4. where is the swing jar?
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 10:58 PM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •