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

📄 helloworld.java

📁 中国水利水电出版社java程序设计教程,附源码
💻 JAVA
字号:
//HelloWorld

import javax.swing.*;
import java.awt.*;

public class HelloWorld
{ 
	public static void main(String[] args)
	{  
		TextFrame frame = new TextFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.show();
	}
}

class TextFrame extends JFrame
{
	public TextFrame()
	{
		setTitle("HelloWorld");
		setSize(WIDTH, HEIGHT);
		
		//将panel加入到frame
		TextPanel panel = new TextPanel();
		Container contentPane = getContentPane();
		contentPane.add(panel);
	}
	
	public static final int WIDTH = 300;
	public static final int HEIGHT = 200;  	
}

class TextPanel extends JPanel
{  
	public void paintComponent(Graphics g)
	{  
		super.paintComponent(g);
		
		//显示文本
		g.drawString(" Hello, World!", x, y);
	}
	
	public int x = 100;
	public int y = 100;
}

⌨️ 快捷键说明

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