GUI programming study notes nine-Swing related (simple operation)
Introduction
- Graphical interface package newly developed to solve the problems of AWT. Swing is an improvement and expansion of AWT.
- The general usage is similar to that of AWT, except that there is something more. When using it, add a j
Simply create windows, set colors, add labels
package pers.ylw.lesson04;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo {
public void init(){
JFrame jFrame = new JFrame("这是一个JFrame窗口");
jFrame.setVisible(true);
jFrame.setBounds(100,100,300,300);
JLabel jLabel = new JLabel("文字");
jLabel.setHorizontalAlignment(SwingConstants.CENTER);
jFrame.add(jLabel);
Container container = jFrame.getContentPane();
container.setBackground(Color.YELLOW);
jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JFrameDemo().init();
}
}