⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helloworld.java

📁 主要是对于JAVA的编程的基本语言 希望能够帮得上你。
💻 JAVA
字号:
package swing;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class HelloWorld extends JFrame implements ActionListener{
	
	JButton btnOK,btnCancel;
	JLabel lblWelcome;
	
	public HelloWorld(String title){
		super(title);
		initialize();
	}

	private void initialize() {		
		//创建组件		
		JButton btnOK=new JButton("确定");
		JButton btnCancel=new JButton("取消");
		lblWelcome=new JLabel("欢迎使用Swing编写窗口程序");
		//添加组件
		this.getContentPane().add(btnOK,"North");		
		this.getContentPane().add(lblWelcome,"Center");
		this.getContentPane().add(btnCancel,"South");
		//设置属性				
		this.pack();
//		int screenWidth=(int)Toolkit.getDefaultToolkit().
//			getScreenSize().getWidth();
//		int screenHeight=(int)Toolkit.getDefaultToolkit().
//			getScreenSize().getHeight();
//		this.setLocation((screenWidth-this.getWidth())/2,
//				(screenHeight-this.getHeight())/2);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		//注册监听器
		btnOK.addActionListener(this);
		btnCancel.addActionListener(this);
	}

	public static void main(String[] args) {
		new HelloWorld("My Swing Application");		
	}

	//编写事件处理代码
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("确定")){
			lblWelcome.setText("你单击了【确定】");		
		}else if(e.getActionCommand().equals("取消")){
			lblWelcome.setText("你单击了【取消】");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -