package com.demo1;
import javax.swing.*;
public class SimpleGUI1{
public static void main(String[] args) {
JFrame frame = new JFrame(); //創建frame
JButton button = new JButton("Click me"); //創建button
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 這一行程序會在Windows關閉時把程序結束掉
frame.getContentPane().add(button); //把button加到frame的pane上
frame.setSize(300, 300); // 設定frame的大小
frame.setVisible(true); // 最後把frame顯示出來
}
}
運行結果:
關注公衆號:工控技術之家,可留言提問相關問題,有需要可發送源代碼