1 2 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
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.nio.charset.*;
public class Test extends JFrame implements ActionListener{
JTextField text;
/**
* @param args
*/
public Test() {
super("test");
text = new JTextField();
JButton button1 = new JButton("Click on me");
setLayout(new BorderLayout());
add(text, BorderLayout.NORTH);
add(button1, BorderLayout.SOUTH);
setSize(800,600);
setVisible(true);
button1.addActionListener(this);
}
public static void main(String[] args) {
new Test();
}
public void actionPerformed(ActionEvent arg0) {
System.out.println(new String(text.getText().getBytes(), Charset.forName("UTF-8")));
}
} |
Partager