helloworld.java~28~
来自「提供了常用的JAVA技术的示例」· JAVA~28~ 代码 · 共 51 行
JAVA~28~
51 行
package helloworld;import javax.swing.*;import java.awt.*;import java.io.*;public class helloworld { boolean packFrame = false; //Construct the application public helloworld() { Frame1 frame = new Frame1(); JPanel panel = new JPanel(); JButton button=new JButton("sunxiaomei"); panel.add(button); System.out.println(button); frame.contentPane.add(panel); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } //Main method public static void main(String[] args) { System.out.println("helloworld!"); System.out.println("第一个小程序!"); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } new helloworld(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?