java用户界面窗口
Posted 辰峰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java用户界面窗口相关的知识,希望对你有一定的参考价值。
java用户界面窗口
窗口框
代码如下:
package Day08; import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
@SuppressWarnings("serial")
public class TestSwingCommonFeatures extends JFrame {
public TestSwingCommonFeatures() {
JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2));
JButton jbtLeft = new JButton("Left");
JButton jbtCenter = new JButton("Center");
JButton jbtRight = new JButton("Right");
jbtLeft.setBackground(Color.WHITE);
jbtCenter.setForeground(Color.GREEN);
jbtRight.setBackground(new Color(10, 100, 100));
jbtRight.setToolTipText("this is the right button");
jp1.add(jbtLeft);
jp1.add(jbtCenter);
jp1.add(jbtRight);
jp1.setBorder(new TitledBorder("3 buttons"));
Border lineBorder = new LineBorder(Color.BLACK, 2);
Font largeFont = new Font("黑体", Font.BOLD, 20);
JPanel jp2 = new JPanel(new GridLayout(1, 2, 5, 5));
JLabel lbl1 = new JLabel("Red");
JLabel lbl2 = new JLabel("Orange");
lbl1.setFont(largeFont);
lbl1.setForeground(Color.RED);
lbl1.setBorder(lineBorder);
lbl2.setForeground(Color.ORANGE);
lbl2.setBorder(lineBorder);
jp2.add(lbl1);
jp2.add(lbl2);
jp2.setBorder(new TitledBorder("2 labels"));
setLayout(new GridLayout(2,1,5,5));
add(jp1);
add(jp2);
}
public static void main(String[] args) {
TestSwingCommonFeatures frame = new TestSwingCommonFeatures();
frame.setTitle("TestSwingCommonFeatures");
frame.setSize(400, 300);//set the frame size
frame.setLocationRelativeTo(null);// center a frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// center a frame
frame.setVisible(true);//display the frame
}
}
以上是关于java用户界面窗口的主要内容,如果未能解决你的问题,请参考以下文章
Java Swing界面编程(21)---事件处理:窗口事件
java swing 我是想把图片作为登录界面的背景,并且需要背景图片能够随窗口大小缩放。。。最好是用标签法
Java AWT 图形界面编程Container 容器 ② ( Frame 窗口示例 | Panel 示例 | 窗口中文乱码处理 )