所以我编写了这段代码,但是当我尝试将它作为 Java 应用程序运行时,控制台什么都不显示,而是终止了。我尝试通过 Preferences-Run/Debug-Console 来调试控制台,以显示程序何时写入标准输出或程序何时写入标准错误但它也不起作用。这是我的代码,提前感谢您的帮助。
import java.awt.*;
import javax.swing.*;
public class Frame4 extends JFrame implements UpdatableView {
private Counter count;
private JLabel label = new JLabel("Number = 0");
private JPanel drawing;
public Frame4(Counter c, JPanel panel) {
count = c;
drawing = panel;
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
p1.add(label);
cp.add(p1, BorderLayout.NORTH);
cp.add(drawing, BorderLayout.CENTER);
JPanel p2 = new JPanel(new FlowLayout());
p2.add(new CountButton("Count", count, this)
setTitle("Frame 4");
setSize(200, 180);
setVisible(true);
}
public void update() {
label.setText("Number = " + count.countOf());
drawing.repaint();
}
public static void main(String[] args) {}
}