代码如下:
package Swing组件;
import javax.swing.*;
import java.awt.*;
public class Demo02 extends JFrame {
public Demo02(){
setBounds(100,100,200,100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
setVisible(true);
JLabel l = new JLabel("这是一个标签");
// l.setText("更改标签");
// System.out.println(l.getText())
l.setFont(new Font("楷体",Font.BOLD,15));
l.setForeground(Color.RED);
c.add(l);
}
public static void main(String[] args) {
new Demo02();
}
}
运行结果:

本文展示了一个使用Java Swing创建简单窗口应用程序的示例代码。通过继承JFrame类并设置窗口大小、关闭操作、可见性及添加JLabel组件,演示了基本的Swing组件使用方法。
2877

被折叠的 条评论
为什么被折叠?



