您的位置:首页 > 产品设计 > UI/UE

GUI

2015-08-14 21:18 471 查看
今天接触了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();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: