之前博客不用了!!!java
1窗口界面:在窗口中加入标签,文本行,按钮三个组件;spa
2窗口功能:在文本行中输入一行字符串后,点击按钮,文本行中的字符串出如今标签中。code
import java.awt.*; import java.awt.event.*; import javax.swing.*; @SuppressWarnings("serial") public class S1 extends JFrame{ private JLabel label = new JLabel(); private JTextField jtf = new JTextField(); private JButton jbt = new JButton("OK"); public S1() { JPanel p = new JPanel(new GridLayout(3,1)); p.add(label); p.add(jtf); p.add(jbt); add(p, BorderLayout.CENTER); jbt.addActionListener(new ButtonListener()); } public class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e) { String text = jtf.getText(); label.setText(text); } } public static void main(String[] args) { JFrame frame = new S1(); frame.setTitle("图形界面实验1"); frame.setSize(300,300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }