Can I create window object instead of frame? I mean when I am creating a window object with an existing frame and showing it nothing happens.
Frame frame=new Frame();
Window window=new Window(frame);
window.show(); // nothing happens here
Can I create window object instead of frame? I mean when I am creating a window object with an existing frame and showing it nothing happens.
Frame frame=new Frame();
Window window=new Window(frame);
window.show(); // nothing happens here
你必须通过调用来显示框架.setVisible(true)
,你可以这样做:
JFrame frame = new JFrame("Title of the Frame");
frame.setVisible(true);
如果你只想要一个里面有东西的窗口,你应该使用 JFrame。下面的示例将创建一个包含两个按钮的窗口。
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SSCCE {
public static void main(String[] args) {
JFrame frame = new JFrame("Title of the Frame");
JPanel panel = new JPanel();
JButton b1 = new JButton("Button 1");
JButton b2 = new JButton("Button 2");
panel.add(b1);
panel.add(b2);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}