之前博客不用了!!!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); } }