| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 
 |  
import javax.swing.*;
import java.awt.Color;
import java.awt.event.*;
import java.awt.BorderLayout;
public class Test implements ActionListener {
	JButton button;
	JTextField textField;
	JFrame jf;
	public Test() {
		button=new JButton("Click");
		textField=new JTextField();
		button.setPreferredSize(new java.awt.Dimension(100,50));
		textField.setPreferredSize(new java.awt.Dimension(200,20));
		button.addActionListener(this);
		jf=new JFrame();
		jf.getContentPane().setLayout(new BorderLayout());
		jf.getContentPane().add(button,BorderLayout.SOUTH);
		jf.getContentPane().add(textField,BorderLayout.NORTH);
		jf.pack();
		jf.setVisible(true);
 
	}
	public void actionPerformed(ActionEvent e){
	 	String message="This is a message text";
		JTextArea jt=new JTextArea(message);
		jt.setEditable(false);
		jt.setBackground(new Color(255,255,177));
		JOptionPane.showMessageDialog(jf,jt,"about",JOptionPane.INFORMATION_MESSAGE);
	}
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				new Test();
			}
		});
	}
} | 
Partager