Advertisement
huyhung94

GUI

Jul 6th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. package Dictionary;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.FlowLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import javax.swing.*;
  8.  
  9. /**
  10.  *
  11.  * @author HuyHung
  12.  */
  13. public class GUI extends JFrame{
  14.  
  15.     private JPanel pn_all, pn_left, pn_right, pn_top;
  16.     private JTextField tf_word;
  17.     private JButton bt_search, bt_add, bt_edit, bt_delete, bt_save;
  18.     private JList l_word;
  19.     private DefaultListModel dlm_word = new DefaultListModel();
  20.     private JLabel lb_icon;
  21.     private JEditorPane edt_mean;
  22.  
  23.     //Creat GUI
  24.     public GUI() throws Exception {
  25.         this.setSize(600, 500);
  26.         setLocation(250,10);
  27.         setResizable(false);
  28.         //Panel Tren cung
  29.         JMenuBar mnb=new JMenuBar();
  30.         JMenu mn_File=new JMenu("File");
  31.             JMenuItem mni_e=new JMenuItem("Exit");
  32.             mn_File.add(mni_e);
  33.         JMenu mn_Help=new JMenu("Help");
  34.             JMenuItem mni_h=new JMenuItem("About");
  35.             mn_Help.add(mni_h);
  36.         mnb.add(mn_File);
  37.         mnb.add(mn_Help);
  38.         lb_icon = new JLabel(new ImageIcon("Banner.png"));
  39.         JPanel pn_tren = new JPanel(new FlowLayout());
  40.         pn_tren.add(lb_icon,BorderLayout.CENTER);
  41.         pn_top = new JPanel(new BorderLayout());      
  42.         pn_top.add(mnb,BorderLayout.NORTH);
  43.         pn_top.add(pn_tren,BorderLayout.CENTER);
  44.         //Panel Ben Trai
  45.         pn_left = new JPanel(new BorderLayout());
  46.             //Box gom textfied + button search,
  47.             Box b_top = Box.createHorizontalBox();
  48.                 tf_word = new JTextField(15);
  49.                 b_top.add(tf_word);                
  50.                 bt_search = new JButton("Search");                
  51.                 b_top.add(bt_search);
  52.                
  53.             //Box gom button Add, Edit, Delete
  54.             Box b_center = Box.createHorizontalBox();
  55.                 bt_add = new JButton("Add");                
  56.                 b_top.add(bt_add);
  57.                 bt_edit = new JButton("Edit");                
  58.                 b_top.add(bt_edit);
  59.                 bt_delete = new JButton("Delete");                
  60.                 b_top.add(bt_delete);
  61.            
  62.             //Box gom JList
  63.             Box b_bottom = Box.createVerticalBox();                
  64.                 b_bottom.add(new JScrollPane(l_word =new JList(dlm_word)));
  65.                
  66.             pn_left.add(b_top,BorderLayout.NORTH);
  67.             pn_left.add(b_bottom,BorderLayout.CENTER);
  68.            
  69.         pn_right = new JPanel(new BorderLayout());
  70.             edt_mean = new JEditorPane();
  71.             pn_right.add(edt_mean);
  72.          Box b_bot = Box.createHorizontalBox();        
  73.             b_bot.add(pn_left);
  74.             b_bot.add(pn_right);        
  75.        
  76.        
  77.         pn_all = new JPanel(new BorderLayout());
  78.         pn_all.add(pn_top,BorderLayout.NORTH);
  79.         pn_all.add(b_bot,BorderLayout.CENTER);
  80.         add(pn_all);
  81.        
  82.         mni_h.addActionListener(new ActionListener() {         
  83.             @Override
  84.             public void actionPerformed(ActionEvent e) {
  85.                 JOptionPane.showMessageDialog(null, "====Code by Chang Che Hiep===");              
  86.             }
  87.  
  88.             });  
  89.         mni_e.addActionListener(new ActionListener() {
  90.            
  91.             @Override
  92.             public void actionPerformed(ActionEvent e) {
  93.                 System.exit(1);            
  94.             }
  95.             });  
  96.     }
  97.     public static void main(String[] args) throws Exception {
  98.         GUI a = new GUI();
  99.         a.setVisible(true);
  100.         a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  101.         a.setTitle("Dictionary ver 1.0");
  102.     }
  103.    
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement