Results 1 to 2 of 2

Thread: Gui

  1. #1
    mamoonrizwan is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Gui

    i have placed JButton and JLabel.
    i want that when i press the button i must be able to get a prompt to enter a string to the label and then the label should be displayed

    this is what i did


    import javax.swing.JFrame;
    import javax.swing.*;
    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class EventHander extends JFrame{

    JButton button1;
    JLabel label1;


    public EventHander(){

    super("Image ");
    setLayout (new FlowLayout());

    button1 = new JButton ("Click");
    label1 = new JLabel("");


    add(button1);
    add(label1);




    event e = new event();
    button1.addActionListener(e);
    }
    public class event implements ActionListener{
    public void actionPerformed(ActionEvent e){
    label1.setText(" i am mamoon rizwan");

    }
    }


    public static void main (String args[]){
    EventHander handle = new EventHander();
    handle.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
    handle.setVisible(true);
    handle.setSize(500,500);

    }
    }

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

    Default

    What problems are you having with your code?

    BTW:
    Class names should begin with a Capital letter: Event
    Also you shouldn't use the java of a Java class when naming your classes: event

    Please edit your code and wrap it in code tags. Use the #icon above the input box.

Tags for this Thread

Posting Permissions

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