GUI

        今天接触了GUI的一些基本类如:

package myjframe;


import java.awt.Color;
import java.awt.Font;
import java.awt.Image;


import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;


//继承JFrame类
public class JFrameTest extends JFrame {

public JFrameTest(){
//设置窗体标题
this.setTitle("Java");
//设置布局管理器为绝对布局,允许用户通过定义组件的大小和位置来安放组件
this.setLayout(null);
//设置作为窗口图标显示图像
this.setIconImage(new ImageIcon("img\\eclipse_update_120.jpg").getImage());

//创建文本框对象
JTextField jt=new JTextField();
//设置文本框的位置和大小
jt.setBounds(100,100,120,20);
//设置背景色
// jt.setBackground(Color.GREEN);
//将文本框加入窗体
this.add(jt);

//创建文字标签
JLabel jl=new JLabel("用户名");
jl.setForeground(new Color(0,210,20));
//设置文字标签的位置
jl.setBounds(30,100,80,20);
//将标文字签加入窗体
this.add(jl);

//创建文字标签
JLabel jla=new JLabel("XX管理系统");
jla.setBounds(300,30,200,30);
//设置标签的字体
jla.setFont(new Font("黑体",Font.BOLD,30));
//设置标签颜色
jla.setForeground(Color.blue);
this.add(jla);

//单选框
JRadioButton jr=new JRadioButton("男");
jr.setBounds(50, 150, 100, 20);
this.add(jr);

JRadioButton jr1=new JRadioButton("女");
jr1.setBounds(150, 150, 100, 20);
this.add(jr1);

//创建按钮组,完成单选框互斥
ButtonGroup bg=new ButtonGroup();
bg.add(jr);
bg.add(jr1);

//复选框
JCheckBox jc=new JCheckBox("体育");
jc.setBounds(50, 200, 80, 20);
this.add(jc);

//按钮
JButton b=new JButton("确定");
b.setBounds(50, 250, 80, 20);
this.add(b);

//下拉框
JComboBox c=new JComboBox();
c.setBounds(50, 300, 120, 20);
this.add(c);
c.addItem("高中");
c.addItem("大学");
c.addItem("初中");

//文本域,多行文本
JTextArea t=new JTextArea();
t.setBounds(50, 350, 100, 100);
//自动换行
t.setLineWrap(true);
this.add(t);


//创建图片标签
//得到图片对象
Image img=new ImageIcon("img\\genre-finearts.jpg").getImage();
//将图片等比缩放到指定大小
img=img.getScaledInstance(800, 600, 1);
JLabel jimg=new JLabel(new ImageIcon(img));
jimg.setBounds(0, 0, 800, 600);
this.add(jimg);



//设置窗体大小
this.setSize(800,600);
//设置窗体可见
this.setVisible(true);
//设置窗体关闭程序结束
this.setDefaultCloseOperation(3);
//设置窗体相对于屏幕居中
this.setLocationRelativeTo(null);
}


public static void main(String[] args) {
JFrameTest j=new JFrameTest();


}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值