java设计简单的swing(java swing表格实例制作,简单两行两列,在线等)
本文目录
- java swing表格实例制作,简单两行两列,在线等
- 用java设计一个简单的界面设计,越简单越好,谢谢
- 求助java的swing窗体怎么做如图布局效果
- 我想知道如何用java swing设计我想要的这样的一个界面望抽空帮助,万分感谢!
- 用java 基于SWING的图形用户界面设计 编写一个应用程序
- 用java编写一个登录界面,用SWING组件
- java设计一个求三角形面积的图形界面,要求通过3个输入框输入3个边长
- 一个java程序 基于Swing的图形用户界面设计
java swing表格实例制作,简单两行两列,在线等
import *****.*;
import *****.*;
import *****.*;
import *****.*;
public class test2
{
public test2(){
JFrame f=new JFrame();
Object playerInfo={
{"王鹏",new Integer(100),new Integer(80),new Boolean(true)},
{"**",new Integer(20),new Integer(30),new Boolean(false)},
{"张鹏",new Integer(89),new Integer(60),new Boolean(true)}
};
String Names={"姓名","英语","数学","blue"};
JTable table=new JTable(playerInfo,Names);
*****(new Dimension(550,60));//设置此表视口的首选大小。
JScrollPane scrollPane=new JScrollPane(table);
*****(scrollPane);
*****("支持蓝鹰");
*****();
*****(true);
*****(*****_ON_CLOSE);
}
public static void main(String args){
new test2();
}
};
用java设计一个简单的界面设计,越简单越好,谢谢
用java设计一个简单的界面可以参考如下实例:
import *****;//框架
import *****;//面板
import *****;//按钮
import *****;//标签
import *****;//文本框
import *****;//字体
import *****;//颜色
import *****;//密码框
import *****;//事件**
import *****;//事件处理
import *****;//消息窗口public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;
public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}
public void userInit(){
*****(*****_ON_CLOSE);//设置关闭框架的同时结束程序
*****(300,200);//设置框架大小为长300,宽200
*****(false);//设置框架不可以改变大小
*****("用户登录");//设置框架标题
*****(null);//设置面板布局管理
*****(*****);//设置面板背景颜色
*****("用户登录");//设置标签标题
*****(new Font("宋体",***** | *****,14));//设置标签字体
*****(*****);//设置标签字体颜色
*****("用户名:");
*****("密 码:");
*****("登录");
*****("重置");
*****(120,15,60,20);//设置标签x坐标120,y坐标15,长60,宽20
*****(50,55,60,20);
*****(50,85,60,25);
*****(110,55,120,20);
*****(110,85,120,20);
*****(85,120,60,20);
*****(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
*****(155,120,60,20);
*****(new ActionListener()//匿名类实现ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
*****(lbluserLogIn);//加载标签到面板
*****(lbluserName);
*****(lbluserPWD);
*****(txtName);
*****(pwdPwd);
*****(btnSub);
*****(btnReset);
*****(pnluser);//加载面板到框架
*****(true);//设置框架可显
}
public void btnsub_ActionEvent(ActionEvent e){
String name = *****();
String pwd = *****(*****());
if(*****("")){
*****(null,"账号不能为空","错误",*****_MESSAGE);
return;
}else if (*****("")){
*****(null,"密码不能为空","错误",*****_MESSAGE);
return;
}else if(true){
*****();
}else{
*****(null,"账号或密码错误","错误",*****_MESSAGE);
return;
}
}
public void btnreset_ActionEvent(ActionEvent e){
*****("");
*****("");
}
public static void main(String args){
new UserLogIn();
}
}
求助java的swing窗体怎么做如图布局效果
运行效果
代码
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
public class TestWin extends JFrame implements ActionListener{
private JLabel numLabel=new JLabel("15");
private JButton startBtn=new JButton("Start");
private JButton stopBtn=new JButton("Stop");
private JButton speedUpBtn=new JButton("Speed Up");
private JButton slowDownBtn=new JButton("Slow Down");
{
*****(this);
*****(this);
*****(this);
*****(this);
Container con=getContentPane();
*****(new BoxLayout(con, *****_AXIS));
*****(new Font("",*****,60));
Box numBox=*****();
*****(numLabel);
add(numBox);
Box btnBox=*****();
*****(startBtn);
*****(stopBtn);
*****(speedUpBtn);
*****(slowDownBtn);
add(btnBox);
setTitle("Thread Test");
setSize(400, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String args) {
*****(() -》 new TestWin());
}
}
我想知道如何用java swing设计我想要的这样的一个界面望抽空帮助,万分感谢!
效果图
思路:
JTabbedPane 提供了一个setUI方法,来修改JTabbedPane 的界面和外观
然后我们可以继承BasicTabbedPaneUI 重写里面的部分绘制方法来修改外观
参考代码
import *****.*;
import *****.*;
import *****.*;
import *****;
import *****;
public class SwingDemo extends JFrame implements ActionListener {
JButton jb;
JPanel jp3;
public SwingDemo() {
JTabbedPane jtpTotal = new JTabbedPane();//横向的JTabbedPane ,模块一,模块二...
JTabbedPane jtpa = new JTabbedPane();//模块一,对应的是jtpa
*****(*****);//设置标签在纵向
JPanel jp1 = new JPanel(new BorderLayout());//新建一个JPanel,布局为边界布局
JTextArea jta = new JTextArea();//文本域
*****("人生若只如初见,何事秋风悲画扇.");//文本域的内容
*****(new Font("宋体",*****, 25));//文本域的文字
*****(jta);
JPanel jp2 = new JPanel();
JLabel jl = new JLabel("PI=*****");
*****(new Font("隶书",*****, 20));
*****(*****);//设置jl的文字颜色
*****(jl);
//为了方便响应事件,把jb,和jp3的定义放到了顶上
jp3 = new JPanel();
jb = new JButton("点击按钮修改本页的背景色");
*****(this);//添加事件响应
*****(jb);
*****("选项一", jp1);
*****("选项二", jp2);
*****("选项三", jp3);
JPanel jpA = new JPanel(new BorderLayout());
*****(jtpa);
//把jtpa的所有选项的标签的背景色设置为白色
for (int i = 0; i 《 *****(); i++) {
*****(i, *****);
}
*****(new TPUI());
*****("模块一", jpA);
//下面的jtpb和jtpc没有添加组件,也没有设置颜色, 但是结构看起来比较直观
JTabbedPane jtpb = new JTabbedPane();
*****(*****);
JPanel jp4 = new JPanel();
JPanel jp5 = new JPanel();
JPanel jp6 = new JPanel();
*****("选项四", jp4);
*****("选项五", jp5);
*****("选项六", jp6);
JPanel jpB = new JPanel(new BorderLayout());
*****(jtpb);
*****("模块二", jpB);
JTabbedPane jtpc = new JTabbedPane();
*****(*****);
JPanel jp7 = new JPanel();
JPanel jp8 = new JPanel();
JPanel jp9 = new JPanel();
*****("选项七", jp7);
*****("选项八", jp8);
*****("选项九", jp9);
JPanel jpC = new JPanel(new BorderLayout());
*****(jtpc);
*****("模块三", jpC);
add(jtpTotal);
setTitle("主窗口");// 标题
setSize(620, 480);// 大小
setLocationRelativeTo(null);// 居中
setDefaultCloseOperation(EXIT_ON_CLOSE);// 关闭窗口后退出程序
setVisible(true);// 窗口可见
}
public static void main(String args) {
new SwingDemo();
}
@Override
public void actionPerformed(ActionEvent e) {//点击修改jp3的颜色
if(*****()==jb){//如果是jb按钮被点击
*****(new Color(getInt(),getInt(),getInt()));//那么修改jp3的背景色
}
}
public int getInt(){//随机产生0~255之间的数字,用于生成随机颜色r,g,b
return (int) (*****()*256);
}
}
//注意,此类用于修改外观JTabbedPane
class TPUI extends BasicTabbedPaneUI {
public static ComponentUI createUI(JComponent c) {
return new TPUI();
}
@Override
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h,
boolean isSelected) {
if (isSelected) {//如果该标签被选中, 那么绘制矩形
*****(new Color(116, 168, 231));
*****(x + w - 10, y, x+w, h);
}else{//没有被选中时的边框, 也可以不用绘制
*****(new Color(116, 168, 231));
*****(x + w - 8, y, x+w, h);
}
}
@Override
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h,
boolean isSelected) {
*****(*****);
*****(g, tabPlacement, tabIndex, x, y, w, h, false);
// 最后一个参数 true绘制背景色.false不绘制
// 如果参数是isSelected ,那么选中就绘制背景色,不选中就不绘制
}
}
用java 基于SWING的图形用户界面设计 编写一个应用程序
package heh;//我自己的包名
import *****.*;
import *****.*;
import *****.*;
import *****.*;
public class Jsq extends JFrame
{
Panel pan1=new Panel();
Panel pan2=new Panel();
Panel pan3=new Panel();
Panel pan4=new Panel();
Panel pan5=new Panel();
Label la1=new Label("欢迎使用计算器");
Button bt1=new Button(" ");
Button bt2=new Button("MC");
Button bt3=new Button("MR");
Button bt4=new Button("MS");
Button bt5=new Button("M+");
Button bt11=new Button("Backspace");
Button bt12=new Button("CE");
Button bt13=new Button("C");
Button but;
String buta={"7","8","9","/","sqrt","4","5","6","*","%","1","2","3","-","1/x","0","-/+",".","+","="};
JTextField t1=new JTextField("0");//swing组件,可以设置对齐方式
double a=0;//记录计算中的值或结果
String b="";//“+,-,*,/”运算符号标记
int d=0; //是否刚刚按过运算符号标记
int x=0; //是否刚刚按过“=”号标记
int y=0; //屏幕刚刚出现过汉字的标记
public Jsq()
{
super("计算器");
add(pan1,*****);
add(pan4,*****);
add(pan3,*****);
*****(new GridLayout(0,1,10,10));
*****(bt1);*****(bt2);*****(bt3);*****(bt4);*****(bt5);
*****(new BorderLayout());
*****(pan5,*****);
*****(pan2,*****);
*****(new GridLayout(1,3,5,5));
*****(bt11);*****(bt12);*****(bt13);
*****(new GridLayout(3,1));
*****(la1);
*****(t1);
*****(false);//文本框设置为不可修改
*****(*****);//设置文本框对齐方式
*****(new GridLayout(4,5,10,10));
for(int i=0;i《20;i++)
{
but);
*****(but);
}
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
*****(new A());
}
class A implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(*****()==but) //"7"
{
if(x==1) //判断是否刚刚按过"="
{
*****("7");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{ //如果显示为"0"或"***"或者刚刚按过运算符号
*****("7"); //或者屏幕显示为汉字 那么显示为"7"
y=0;//将标记设置为0
}
else
*****(*****()+"7");//将显示的字符串后面加"7"
d=0;//将标记设置为0
if(*****().length()》40)//判断显示字符长度是否超过40
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"8"
{
if(x==1)
{
*****("8");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("8");
y=0;
}
else
*****(*****()+"8");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"9"
{
if(x==1)
{
*****("9");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("9");
y=0;
}
else
*****(*****()+"9");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"/"
{
if(y==1) //判断显示的是否为汉字
{
*****("0");
y=0;
}
if(d==0) //判断是否刚刚按过运算符号 防止连续按运算符号产生错误
{
if(*****("+"))//四则混合运算时 判断上次计算是否为"+"
{
a=a+*****(*****()).doubleValue();
*****(""+a);
}
if(*****("-"))//四则混合运算时 判断上次计算是否为"-"
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(*****("*"))//四则混合运算时 判断上次计算是否为"*"
{
a=a******(*****()).doubleValue();
*****(""+a);
}
if(*****("/"))//四则混合运算时 判断上次计算是否为"/"
{
double f=*****(*****()).doubleValue();
if(f==0)//判断除数是否为0
{
*****("错误!请按“CE”清屏后继续计算");
y=1;
}
else
{
a=a/*****(*****()).doubleValue();
*****(""+a);
}
}
if(*****(""))//判断进行的是不是四则混合运算的第一次运算
{
a=*****(*****()).doubleValue();
*****(""+a);
}
}
if(!*****().equals("错误!请按“CE”清屏后继续计算"))//是否出现了除数为零的错误
{
b="/";//运算符号标记设置为"/"
d=1; //标记已经按过运算符号
}
if(*****().length()》40)//判断显示字符长度是否超过40
{
*****("错误!数字过长,请按“C”从新输入");
a=***;//将记忆的数字抹去
b="";//运算符号标记 为未按过运算符号
d=0;//标记 刚刚没有按过运算符号
y=1;//标记 屏幕显示了汉字
}
}
if(*****()==but) //"sqrt"
{
if(y==1)
{
*****("0");
y=0;
}
double f=*****(*****()).doubleValue();
if(f《0) //判断被开放数是否小于零
{
*****("错误!被开方数小于0,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
else
{
f=*****(f);
*****(""+(f));
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"4"
{
if(x==1)
{
*****("4");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("4");
y=0;
}
else
*****(*****()+"4");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"5"
{
if(x==1)
{
*****("5");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("5");
y=0;
}
else
*****(*****()+"5");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"6"
{
if(x==1)
{
*****("6");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("6");
y=0;
}
else
*****(*****()+"6");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"*"
{
if(y==1)
{
*****("0");
y=0;
}
if(d==0)
{
if(*****("+"))
{
a=a+*****(*****()).doubleValue();
*****(""+a);
}
if(*****("-"))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(*****("*"))
{
a=a******(*****()).doubleValue();
*****(""+a);
}
if(*****("/"))
{
double f=*****(*****()).doubleValue();
if(f==0)
{
*****("错误!请按“CE”清屏后继续计算");
y=1;
}
else
{
a=a/*****(*****()).doubleValue();
*****(""+a);
}
}
if(*****(""))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
}
if(!*****().equals("错误!请按“CE”清屏后继续计算"))
{
b="*";
d=1;
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"%"
{
if(y==1)
{
*****("0");
y=0;
}
double f=*****(*****()).doubleValue();
*****(""+(f/100));
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"1"
{
if(x==1)
{
*****("1");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("1");
y=0;
}
else
*****(*****()+"1");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"2"
{
if(x==1)
{
*****("2");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("2");
y=0;
}
else
*****(*****()+"2");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"3"
{
if(x==1)
{
*****("3");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("3");
y=0;
}
else
*****(*****()+"3");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"-"
{
if(y==1)
{
*****("0");
y=0;
}
if(d==0)
{
if(*****("+"))
{
a=a+*****(*****()).doubleValue();
*****(""+a);
}
if(*****("-"))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(*****("*"))
{
a=a******(*****()).doubleValue();
*****(""+a);
}
if(*****("/"))
{
double f=*****(*****()).doubleValue();
if(f==0)
{
*****("错误!请按“CE”清屏后继续计算");
y=1;
}
else
{
a=a/*****(*****()).doubleValue();
*****(""+a);
}
}
if(*****(""))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
}
if(!*****().equals("错误!请按“CE”清屏后继续计算"))
{
b="-";
d=1;
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"1/x"
{
if(y==1)
{
*****("0");
y=0;
}
else
{
double f=*****(*****()).doubleValue();
*****(""+(1/f));
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
}
if(*****()==but) //"0"
{
if(x==1)
{
*****("0");
x=0;
}
if(*****().equals("***")||*****().equals("0")||d==1||y==1)
{
*****("0");
y=0;
}
else
*****(*****()+"0");
d=0;
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"-/+"
{
if(y==1)
{
*****("0");
y=0;
}
double f=*****(*****()).doubleValue();
*****(""+(-f));
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"."
{
if(y==1)
{
*****("0");
y=0;
}
if(*****().indexOf(".")==-1)//判断是否已经有"."
{
*****(*****()+".");
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"+"
{
if(y==1)
{
*****("0");
y=0;
}
if(d==0)
{
if(*****("+"))
{
a=a+*****(*****()).doubleValue();
*****(""+a);
}
if(*****("-"))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(*****("*"))
{
a=a******(*****()).doubleValue();
*****(""+a);
}
if(*****("/"))
{
double f=*****(*****()).doubleValue();
if(f==0)
{
*****("错误!请按“CE”清屏后继续计算");
y=1;
}
else
{
a=a/*****(*****()).doubleValue();
*****(""+a);
}
}
if(*****(""))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
}
if(!*****().equals("错误!请按“CE”清屏后继续计算"))
{
b="+";
d=1;
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==but) //"="
{
if(y==1)
{
*****("0");
y=0;
}
if(*****("+"))
{
a=a+*****(*****()).doubleValue();
*****(""+a);
}
if(*****("-"))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(*****("*"))
{
a=a******(*****()).doubleValue();
*****(""+a);
}
if(*****("/"))
{
double f=*****(*****()).doubleValue();
if(f==0)
{
*****("错误!请按“CE”清屏后继续计算");
y=1;
}
else
{
a=a/*****(*****()).doubleValue();
*****(""+a);
}
}
if(*****(""))
{
a=*****(*****()).doubleValue();
*****(""+a);
}
if(!*****().equals("错误!请按“CE”清屏后继续计算"))
{
b="";
d=1;
x=1;
}
if(*****().length()》40)
{
*****("错误!数字过长,请按“C”从新输入");
a=***;
b="";
d=0;
y=1;
}
}
if(*****()==bt11) //"Backspace"
{
if(y==1)
{
*****("0");
y=0;
}
else
{
String s1=*****();
if(*****()==1)//如果将显示的数字全部退掉 则显示"0"
{
*****("0");
}
else
{
*****(*****(0,(*****()-1)));//退格
}
}
}
if(*****()==bt12) //"CE"
{
*****("0");//清屏
}
if(*****()==bt13) //"C" 初始化
{
*****("0");
a=***;
b="";
d=0;
}
if(*****()==bt1) //""
{
}
if(*****()==bt2) //"MC"
{
}
if(*****()==bt3) //"MR"
{
}
if(*****()==bt4) //"MS"
{
}
if(*****()==bt5) //"M+"
{
}
}
}
public static void main(String args)
{
Jsq a=new Jsq();
*****(300,250);
*****(true);
}
}
用java编写一个登录界面,用SWING组件
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
/**
* 一个简单的Swing窗口,输入内容单击“确定”按钮后,在文本域中显示输入的内容。
* 单击“取消”按钮,清空页面内容。
* @author yzg
*
*/
public class Register extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel nameLabel;
private JTextArea context;
private JTextField name;
private JLabel pLabel;
JList speciality;
JLabel mLabel;
String data = { "计算机", "英语", "机械", "化工" };
ButtonGroup bg;
JRadioButton male;
JRadioButton female;
JLabel fLabel;
JCheckBox faverite1;
JCheckBox faverite2;
JCheckBox faverite3;
JCheckBox faverite4;
public Register(String title) {
super(title);
*****().setLayout(null);
// 下面两行是取得屏幕的高度和宽度
double lx = *****().getScreenSize().getWidth();
double ly = *****().getScreenSize().getHeight();
*****(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 200));// 设定窗口出现位置
*****(340, 440);// 设定窗口大小
}
public void showWin() {
// 确保窗体有一个好的外观装饰
// setDefaultLookAndFeelDecorated(true);
*****(EXIT_ON_CLOSE);
// 姓名
nameLabel = new JLabel("姓名 :");
*****(30, 10, 50, 25);
name = new JTextField();
*****(80, 10, 120, 20);
*****(*****(*****));
*****(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
if (*****().length() 》 6) {
*****(*****().substring(0, 6));
}
}
});
// 专业 组合框
pLabel = new JLabel("专业 :");
*****(30, 40, 50, 25);
speciality = new JList(data);
*****(*****_SELECTION);
*****(80, 40, 80, 85);
*****(*****(*****));
mLabel = new JLabel("性别 :");
*****(30, 130, 50, 25);
// 性别 单选框
bg = new ButtonGroup();
male = new JRadioButton("男");
female = new JRadioButton("女");
*****(male);
*****(female);
*****(80, 130, 60, 25);
*****(140, 130, 60, 25);
fLabel = new JLabel("爱好 :");
*****(30, 160, 50, 25);
// 爱好 复选框
faverite1 = new JCheckBox("音乐");
faverite2 = new JCheckBox("足球");
faverite3 = new JCheckBox("高尔夫");
faverite4 = new JCheckBox("游戏");
*****(80, 160, 60, 25);
*****(140, 160, 60, 25);
*****(200, 160, 65, 25);
*****(265, 160, 60, 25);
// 内容 文本区域
JLabel conLabel = new JLabel("输入的内容 :");
*****(30, 250, 90, 25);
context = new JTextArea();
*****(30, 270, 260, 100);
*****(*****(*****));
// 确定按钮
JButton ok = new JButton("确定");
*****(50, 190, 60, 25);
*****(new MouseListener() {
public void mouseClicked(MouseEvent e) {
StringBuffer ** = new StringBuffer();
**.append(*****()).append(*****());
**.append("\n");
int index = *****();
if (index 》= 0) {
**.append(*****()).append(data);
} else {
**.append(*****());
}
**.append("\n");
**.append(*****());
if (*****()) {
**.append("男");
}
if (*****()) {
**.append("女");
}
**.append("\n");
**.append(*****());
if (*****()) {
**.append("音乐 ");
}
if (*****()) {
**.append("足球 ");
}
if (*****()) {
**.append("高尔夫 ");
}
if (*****()) {
**.append("游戏 ");
}
*****(**.toString());
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
// 取消按钮
JButton cancel = new JButton("取消");
*****(120, 190, 60, 25);
*****(new MouseListener() {
public void mouseClicked(MouseEvent e) {
*****("");
*****();
if (*****()) {
*****(false);
}
if (*****()) {
*****(false);
}
if (*****()) {
*****(false);
}
if (*****()) {
*****(false);
}
*****("");
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
});
*****().add(nameLabel);
*****().add(name);
*****().add(pLabel);
*****().add(speciality);
*****().add(mLabel);
*****().add(male);
*****().add(female);
*****().add(fLabel);
*****().add(faverite1);
*****().add(faverite2);
*****().add(faverite3);
*****().add(faverite4);
*****().add(conLabel);
*****().add(context);
*****().add(ok);
*****().add(cancel);
// *****();
*****(true);
}
/**
* @param args
*/
public static void main(String args) {
Register reg = new Register("Register");
*****();
}
}
java设计一个求三角形面积的图形界面,要求通过3个输入框输入3个边长
下面是一个简单的 Java Swing 实现,包含三个文本框用于输入三角形的三条边:
```java
import *****.*;
import *****;
import *****;
import *****.*;
public class TriangleAreaCalculator extends JFrame {
private JLabel label1, label2, label3, resultLabel, errorLabel;
private JTextField tf1, tf2, tf3;
private JButton calculateButton;
public TriangleAreaCalculator() {
setTitle("Triangle Area Calculator"); // 设置窗口标题
setLayout(new GridLayout(5, 2)); // 设置网格布局
// 创建文本标签和文本框
label1 = new JLabel("Enter the length of side 1:");
tf1 = new JTextField(10);
label2 = new JLabel("Enter the length of side 2:");
tf2 = new JTextField(10);
label3 = new JLabel("Enter the length of side 3:");
tf3 = new JTextField(10);
// 创建计算按钮和结果标签
calculateButton = new JButton("Calculate");
resultLabel = new JLabel("");
errorLabel = new JLabel("");
// 添加组件到窗口
add(label1);
add(tf1);
add(label2);
add(tf2);
add(label3);
add(tf3);
add(calculateButton);
add(resultLabel);
add(errorLabel);
// 添加按钮**器
*****(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
double a = *****(*****());
double b = *****(*****());
double c = *****(*****());
if (a + b 《= c || a + c 《= b || b + c 《= a) {
throw new IllegalArgumentException("Invalid input! The sum of any two sides must be greater than the third side.");
}
double s = (a + b + c) / 2;
double area = *****(s * (s - a) * (s - b) * (s - c));
*****(*****("The area of the ******** is: %.2f", area)); // 显示计算结果,保留两位小数
*****(""); // 清除错误提示
} catch (NumberFormatException ex) {
*****("");
*****("Invalid input! Please enter a number.");
} catch (IllegalArgumentException ex) {
*****("");
*****(*****());
}
}
});
pack(); // 使窗口大小自适应内容
setLocationRelativeTo(null); // 将窗口置于屏幕中央
setResizable(false); // 禁止调整窗口大小
setDefaultCloseOperation(EXIT_ON_CLOSE); // 设置窗口关闭行为
}
public static void main(String args) {
TriangleAreaCalculator calculator = new TriangleAreaCalculator();
*****(true);
}
}
```
通过绑定按钮的**器,在输入三边长度后单击 “Calculate” 按钮,程序将计算三角形的面积,并在下方展示计算结果,当用户输入不合法数据时,也会在下方展示错误提示。
一个java程序 基于Swing的图形用户界面设计
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
import *****;
public class NewFrame extends JFrame {
private ***** jButton1;
private ***** jLabel1;
private ***** jLabel2;
private ***** jLabel3;
private ***** jTextField1;
private ***** jTextField2;
private ***** jTextField3;
private int a;
private int b;
private int total = 0;
private int result = 0;
private Random random = new Random();
public NewFrame() {
initComponents();
}
public int getA() {
a = *****(100);
return a;
}
public void setA(int a) {
***** = a;
}
public int getB() {
b = *****(100);
return b;
}
public void setB(int b) {
***** = b;
}
private void initComponents() {
********traints gridBagC***traints;
jTextField1 = new *****();
jLabel2 = new *****();
jTextField2 = new *****();
jLabel3 = new *****();
jTextField3 = new *****();
jButton1 = new *****();
jLabel1 = new *****();
setDefaultCloseOperation(*************_ON_CLOSE);
setTitle("加法测试");
getContentPane().setLayout(new *****());
*****(8);
*****(getA() + "");
*****(false);
getContentPane().add(jTextField1, new ********traints());
*****("加");
getContentPane().add(jLabel2, new ********traints());
*****(8);
*****(false);
*****(getB() + "");
*****(new KeyListener() {
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
if (*****_ENTER == *****()) {
*****("keyPressed");
action();
}
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
});
getContentPane().add(jTextField2, new ********traints());
*****("等于");
getContentPane().add(jLabel3, new ********traints());
*****(8);
getContentPane().add(jTextField3, new ********traints());
*****("确定");
*****(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
action();
}
});
getContentPane().add(jButton1, new ********traints());
*****("总分:0 ");
gridBagC***traints = new ********traints();
gridBagC******** = ***;
gridBagC******** = ***;
getContentPane().add(jLabel1, gridBagC***traints);
pack();
}
private void action() {
try {
if (total 》= 99) {
*****(null, "测试结束" + *****(),
"提示", 1);
*****("测试结束");
return;
}
int a = *****(*****());
int b = *****(*****());
int c = *****(*****().trim());
*****(a + " " + b + " " + c);
if (a + b == c) {
result++;
*****(null, "正确", "正确提示", 1);
} else {
*****(null, "错误", "错误提示", 1);
}
total++;
*****("总分:" + result + " ");
*****(getA() + "");
*****(getB() + "");
*****("");
} catch (Exception e) {
*****(null, "输入提示", "请输入数字", 1);
}
}
public static void main(String args) {
Font font = new Font("宋体", *****, 12);
for (Enumeration keys = *****().keys(); keys
.hasMoreElements();) {
Object key = *****();
Object value = *****(key);
if (value instanceof FontUIResource) {
*****(key, font);
}
}
NewFrame frame = new NewFrame();
*****(null);
*****(400, 200);
*****(true);
}
}
本文相关文章:
phpcms设置权限(phpcms在线投稿后台不设置权限,会员中心还是显示该栏目投稿)
2026年4月28日 11:00
sql sum group by用法(**L 求和语句就是GROUP by的sum,在线等)
2026年4月27日 16:20
静态网页制作考题和答案(网页设计考题 高分!!!在线等!!!)
2026年4月25日 08:40
格式工厂在线转换(jpg在线转换jpeg-如何将jpg图片格式改为jpeg)
2026年4月20日 19:40
免费在线crm(有没有免费的轻量级在线CRM系统可以分享一下)
2026年3月27日 15:20
更多文章:
setselected(android setselected用法以及)
2026年4月29日 15:20
springgateway路由配置(gateway网关配合nacos做动态路由)
2026年4月29日 14:40
虚拟机vim命令(虚拟机centos64位 在Vim中手动配置了ip成功保存后,不能显示)
2026年4月29日 14:00
php socket框架(请教php大神,php如何实现点击页面上的一个按钮发送socket的tcp数据)
2026年4月29日 13:40
java设计简单的swing(java swing表格实例制作,简单两行两列,在线等)
2026年4月29日 13:20
如何制作svg图片(如何使用SVG生成超酷的页面预加载素描动画效果)
2026年4月29日 13:00
git push到远程分支(Git怎么推送本地分支到远程新分支上面去)
2026年4月29日 12:20



