14 April 2016

Show mesager and clear swing

Show mesager and clear
package swing;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class SingApp {

 private JFrame frame;
 private JTextField textField2;
 private JTextField textField1;

 /**
  * Launch the application.
  */
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     SingApp window = new SingApp();
     window.frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }

 /**
  * Create the application.
  */
 public SingApp() {
  initialize();
 }

 /**
  * Initialize the contents of the frame.
  */
 private void initialize() {
  frame = new JFrame();
  frame.setBounds(100, 100, 450, 300);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(null);
  
  textField2 = new JTextField();
  textField2.setBounds(24, 131, 384, 79);
  frame.getContentPane().add(textField2);
  textField2.setColumns(10);
  
  JButton btnNewButton = new JButton("Search");
  btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) { String messager = "Search: "+textField1.getText(); textField2.setText(messager); } }); btnNewButton.setBounds(125, 97, 89, 23); frame.getContentPane().add(btnNewButton); textField1 = new JTextField(); textField1.setBounds(24, 66, 384, 20); frame.getContentPane().add(textField1); textField1.setColumns(10); JButton btnClease = new JButton("Clear"); btnClease.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { textField1.setText(""); textField2.setText(""); } }); btnClease.setBounds(239, 97, 89, 23); frame.getContentPane().add(btnClease); JLabel lblShowMessagerAnd = new JLabel("Show Messager and Clear"); lblShowMessagerAnd.setFont(new Font("Tahoma", Font.PLAIN, 21)); lblShowMessagerAnd.setBounds(102, 11, 272, 32); frame.getContentPane().add(lblShowMessagerAnd); JLabel lblDesignByMr = new JLabel("Design by Mr.24!"); lblDesignByMr.setFont(new Font("Viner Hand ITC", Font.PLAIN, 14)); lblDesignByMr.setBounds(293, 228, 115, 23); frame.getContentPane().add(lblDesignByMr); } }



0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang