Results 1 to 12 of 12
  1. #1
    azzaiel's Avatar
    azzaiel is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default help need basic java swing tuitorial

    does anybody know a basic java swing tutorial?
    It's easy to write a code that computers can understand...
    ... the challenge is to write a code that humans can understand

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    azzaiel's Avatar
    azzaiel is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    thanks for the link!!
    It's easy to write a code that computers can understand...
    ... the challenge is to write a code that humans can understand

  4. #4
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    You can also try the tutorial posted in IBM developerworks- Introduction to Swing

    This is also very good tutorial for beginners.

    For absolute beginners I would recommend Java sun site. See this site also- The Java Swing tutorial
    New to Java/PHP/Javascript development?
    For free help go to- www.techcubetalk.com

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by azzaiel View Post
    thanks for the link!!
    You are welcome. :) And you can find a lot of related tutorials on the web too.

  6. #6
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Tutorial file help please!

    :confused:

    This probably isnt the right pleace for this but as it is a tutorial I didnt want to start a new thread.

    I have been following a tutorial at Menus and toolbars in Java Swing but I cannot compile the .java file.

    Can someone please tell me if it is me that is doing something wrong or if there is actually an error in this file?

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.UIManager;
    
    
    public class Menu extends JFrame {
    
        public Menu() {
    
            setTitle("JMenuBar");
    
            JMenuBar menubar = new JMenuBar();
            ImageIcon icon = new ImageIcon("exit.png");
    
            JMenu file = new JMenu("File");
            file.setMnemonic(KeyEvent.VK_F);
    
            JMenuItem fileClose = new JMenuItem("Close", icon);
            fileClose.setMnemonic(KeyEvent.VK_C);
            fileClose.setToolTipText("Exit application");
            fileClose.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    System.exit(0);
    
            });
    
            file.add(fileClose);
    
            menubar.add(file);
    
            setJMenuBar(menubar);
    
            setSize(250, 200);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
        }
    
        public static void main(String[] args) {
    
            new Menu();
    
        }
    }
    The files previous to this in the tutorial compile fine but this one doesnt.


    Thanks in advance.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Count and match your opening and closing braces. { }

    db

  8. #8
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Thanks, line 32 was the problem, needed 1 more closeing brace. That will teach me not to assume as it was a tutorial.

    Thanks again

  9. #9
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default Java Tutorial error

    :confused:

    I have found another tutorial file that is not compiling, this time I have checked the brace count and as long as I am counting correctly they are all there.

    5 opening braces

    &

    5 closing braces

    When trying to compile I am getting

    SimpleToolbar.java:49: class, interface or enum expected
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JToolBar;
    
    
    public class SimpleToolbar extends JFrame {
    
    
        public SimpleToolbar() {
    
            setTitle("SimpleToolbar");
    
            JMenuBar menubar = new JMenuBar();
            JMenu file = new JMenu("File");
            menubar.add(file);
            setJMenuBar(menubar);
    
            JToolBar toolbar = new JToolBar();
    
            ImageIcon icon = new ImageIcon(getClass().getResource("exit.png"));
    
            JButton exit = new JButton(icon);
            toolbar.add(exit);
            exit.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    System.exit(0);
                }
    
            });
    
    
            add(toolbar, BorderLayout.NORTH);
    
            setSize(300, 200);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
        }
    
        public static void main(String[] args) {
            new SimpleToolbar();
        }
    }

    Could someone just have a quick check of the code for me please and see where the error is?

    Thanks in advance for any help

  10. #10
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    can someone tell me what the error is telling me ?
    SimpleToolbar.java:49: class, interface or enum expected

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

    Default

    Which line is line 49?

  12. #12
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 07:17 PM
  2. basic java
    By vijay24805 in forum New To Java
    Replies: 25
    Last Post: 04-14-2009, 03:46 AM
  3. basic text editor in Swing
    By Java.child in forum AWT / Swing
    Replies: 6
    Last Post: 12-31-2008, 12:09 AM
  4. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 01:36 PM
  5. Help, basic shapes using java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 09:52 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
  •