⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise13_7.java

📁 java程序设计 机械工业出版社 书籍代码
💻 JAVA
字号:
// Exercise13_7.java: Draw a star
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Exercise13_7 extends JFrame implements ActionListener {
  private JTextField jtfHour = new JTextField(2);
  private JTextField jtfMinute = new JTextField(2);
  private JTextField jtfSecond = new JTextField(2);
  private StillClock clock = new StillClock();

  public Exercise13_7() {
    Container container = getContentPane();
    JPanel p = new JPanel();
    p.add(new JLabel("Hour"));
    p.add(jtfHour);
    p.add(new JLabel("Minute"));
    p.add(jtfMinute);
    p.add(new JLabel("Second"));
    p.add(jtfSecond);

    container.add(p, BorderLayout.SOUTH);
    container.add(clock, BorderLayout.CENTER);

    jtfHour.addActionListener(this);
    jtfMinute.addActionListener(this);
    jtfSecond.addActionListener(this);
  }

  public static void main(String[] args) {
    Exercise13_7 frame = new Exercise13_7();
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Exercise13_7");
    frame.setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jtfHour)
      clock.setHour(Integer.parseInt(jtfHour.getText()));
    else if (e.getSource() == jtfMinute)
      clock.setMinute(Integer.parseInt(jtfMinute.getText()));
    else if (e.getSource() == jtfSecond)
      clock.setSecond(Integer.parseInt(jtfSecond.getText()));
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -