Friday, 29 June 2012

Display Simple Profile In Java Swing

Save this file as Profile.java.

01import javax.swing.*;
02import java.awt.*;
03import java.awt.event.*;
04 
05public class Profile extends JFrame {
06  public Profile() {
07    JFrame frame   = new JFrame();
08    Container c    = getContentPane();
09    String name    = "Name: Merry Go Round";
10    String address = "Address: Carnival";
11    String telno   = "Telno: 14344";
12    String profile = name + "\n" + address + "\n" + telno;
13    JTextArea area = new JTextArea(profile);
14 
15    setBounds(400,300,200,100);
16    setTitle("Simple Profile");
17 
18    JButton button = new JButton("Close");
19 
20    c.add (area, BorderLayout.NORTH);
21    c.add(button, BorderLayout.CENTER);
22 
23    button.addActionListener(new ActionListener() {
24      public void actionPerformed(ActionEvent e) {buttonAction();}
25    });
26 
27    show();
28  }
29 
30  void buttonAction() {
31    System.exit(0);
32  }
33 
34  public static void main(String[]args) {
35    Profile show = new Profile();
36    show.setResizable(false);
37 
38  }
39}

0 comments:

Post a Comment

Internet-PublicLab. Powered by Blogger.