Results 1 to 6 of 6
  1. #1
    owj2010 is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default New to GUI Programming in JAVA

    Hi there ,, I'm new to GUI Programming in JAVA ,, just wonder why this code could not run ..

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Week8 extends JFrame {
    
        //Declare the GUI widget
    	JTextArea outputTA = new JTextArea(10,30);
    	JTextField inputTF = new JTextField(30);
    	JButton clearButton = new JButton ("Clear");
    
        public Week8() {
    	
            JPanel panel = new JPanel();
            panel.add(outputTA);
            panel.add(inputTF);
            panel.add(clearButton);
    
            add(panel); // Add panel to the frame
    
             ClearListener cl = new ClearListener();
             clearButton.addActionListener(cl);
             inputTF.addActionListener (new AddListener());
        }
        
           public static void main(String[] args) {
    
    		JFrame frame = new Week8();
                     frame.setTitle("GUI Exercise : Week 8");
                     frame.setSize(200, 150);
                     frame.setLocation(200, 100);
                     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                     frame.setVisible(true);
    
        }
    
    	class AddListener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{ String text = inputTF.getText();
    		  outputTA.append(text + "\n");
    		  inputTF.setText("");
    		}
    	}
    
    	class ClearListener implements ActionListener
    	{ public void actionPerformed (ActionEvent e)
     	  { outputTA.setText("");
    	  }
    	}
    
    }
    Last edited by Eranga; 08-30-2010 at 01:52 PM. Reason: code tags added

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    Did you get any error message when running the program? If you did get an error message can you show us.

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

  4. #4
    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

    What you mean by it's not running? Did you get any errors, if so post the complete error to see here?

    Looking at your code, looking at your layout, you may not seen the content. Maximize the form you may see the controls.

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    It is working in here.What is your problem?
    If your problem is that,window doesnt appear,Check the size of frame.You should increase it.
    Code:
    Java Code:
     frame.setTitle("GUI Exercise : Week 8");
                 frame.setSize(400, 350);
                 frame.setLocation(200, 100);
    I think,you have understood.
    If it is helpful to you,PRESS rep button.

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

Similar Threads

  1. Replies: 27
    Last Post: 06-06-2009, 02:09 AM
  2. Replies: 1
    Last Post: 05-31-2009, 11:57 PM
  3. Replies: 1
    Last Post: 05-31-2009, 07:48 PM
  4. Replies: 1
    Last Post: 05-31-2009, 03:17 PM
  5. Replies: 16
    Last Post: 05-28-2009, 04:41 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
  •