学习java窗口基本操作时无聊写的

学习java窗口基本操作时无聊写的

就当记录

代码如下:

package day08;

import java.awt.BorderLayout;
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.LineBorder;
import javax.swing.border.TitledBorder;

public class Testketianglianxin extends JFrame {
public Testketianglianxin() {

Font font1 = new Font("Serif", Font.BOLD + Font.ITALIC, 20);
Font jbutton1 = new Font("Dialog", Font.PLAIN + Font.BOLD, 20);
Font count1 = new Font("楷体", Font.BOLD + Font.PLAIN, 20);

TitledBorder help = new TitledBorder("hello world");
TitledBorder titledBorder = new TitledBorder("三个按钮");

LineBorder lb1 = new LineBorder(Color.RED,4);
LineBorder lb2 = new LineBorder(Color.ORANGE,4);

JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton btn1 = new JButton("Left");
btn1.setForeground(new Color(FRAMEBITS));
btn1.setToolTipText("00000000");
btn1.setFont(font1);

JButton jbutton = new JButton("center");
jbutton.setForeground(new Color(120, 25, 30));
jbutton.setFont(jbutton1);

JButton jbutton2 = new JButton("Right");
jbutton2.setFont(count1);

p1.add(jbutton);
p1.add(btn1);
p1.add(jbutton2);
JPanel p2 = new JPanel(new GridLayout(1,2));
JLabel label1 = new JLabel("Red");
JLabel label2 = new JLabel("Orange");
p2.add(label1);
p2.add(label2);

label1.setBorder(lb1);
label2.setBorder(lb2);

// Font help1 = new Font("楷体", Font.BOLD + Font.PLAIN, 20);
// 创建边框
// 给p1设置边框
p1.setBorder(titledBorder);
p2.setBorder(help);
setLayout(new GridLayout(2, 1, 5, 5));
add(p1);
add(p2);
}

public static void main(String[] args) {
Testketianglianxin fr = new Testketianglianxin();
fr.setSize(500, 300);
fr.setLocationRelativeTo(null);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setVisible(true);
}
}

上一篇:问题:使用ajax跳转到新页面无效(浏览器Safari)


下一篇:Elasticsearch中JAVA API的使用