[英]Program compiles but does not display GUI on Mac
So far:至今:
TFDemo
public.TFDemo
公开。import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingDemo {
SwingDemo() {
// Create a new JFrame container
JFrame jfrm = new JFrame("A Simple Swing Application");
// Gives the frame an initial size
jfrm.setSize(275, 100);
// Terminate the program when the user closes the application
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a text-based label
JLabel jlab = new JLabel(" GUI programming with Swing.");
// Add the label to the content pane
jfrm.add(jlab);
// Display the frame
jfrm.setVisible(true);
}
public static void main(String[] args) {
// Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
}
});
}
}
You didn't create the frame at the commented block!您没有在评论区创建框架!
public static void main(String[] args) {
// Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new SwingDemo();
}
});
}
Also, here it would seem a good idea to let your program exit when you close the primary frame... so add something like,此外,在这里关闭主框架时让程序退出似乎是个好主意......所以添加类似的东西,
// Add the label to the content pane
jfrm.add(jlab);
// Exit on close
jfrm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Display the frame
jfrm.setVisible(true);
And running on a mac并在 Mac 上运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.