很简单 就是一个界面 点击按钮显示hello
追答package say; import java.awt.BorderLayout; import java.awt.Font; import java.awt.event.*; import javax.swing.*; public class SayHello extends JFrame { public static void main(String[] args) { new SayHello("SayHello").display();; } public void display(){ setVisible(true); } private int times; private JLabel label; private JTextArea textArea; private JButton hello; private JButton clear; private JScrollPane scrollPane ; public SayHello(String title){ super(title); init(); initLabel(); initTextArea(); initButton(); initListener(); } private void init(){ setResizable(false); setSize(400, 350); setDefaultCloseOperation(EXIT_ON_CLOSE); } private void initLabel(){ label = new JLabel("you have clicked " + times +" times",JLabel.CENTER); add(label, BorderLayout.NORTH); } private void initTextArea(){ textArea = new JTextArea(); textArea.setFont(new Font(Font.SERIF, Font.PLAIN, 18)); scrollPane = new JScrollPane(textArea); scrollPane.setAutoscrolls(true); add(scrollPane, BorderLayout.CENTER); } private void initButton(){ hello = new JButton("Hello!"); clear = new JButton("Clear"); JPanel pan = new JPanel(); pan.add(hello); pan.add(clear); add(pan, BorderLayout.SOUTH); } private void initListener(){ hello.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(times > 0) textArea.append("\n"); textArea.append("Hello!"); times++; updateTimes(times); } }); clear.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { textArea.setText(""); times = 0; updateTimes(times); } }); } private void updateTimes(int times){ label.setText("you have clicked " + times +" times"); } }