java设计简单的swing(java swing表格实例制作,简单两行两列,在线等)

:暂无数据 2026-04-29 13:20:02 0
本文旨在解决您关于java设计简单的swing的两大困惑:一是理清基本概念,二是深入解析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);
}
}

纸上得来终觉浅,绝知此事要躬行。java设计简单的swingjava swing表格实例制作,简单两行两列,在线等的理论已备好,期待你的实践成果。
本文编辑:admin

本文相关文章:


phpcms设置权限(phpcms在线投稿后台不设置权限,会员中心还是显示该栏目投稿)

phpcms设置权限(phpcms在线投稿后台不设置权限,会员中心还是显示该栏目投稿)

回顾我学习phpcms设置权限的经历,phpcms在线投稿后台不设置权限,会员中心还是显示该栏目投稿可算是一个重要的转折点。正是搞懂了它,一切才变得顺畅起来。

2026年4月28日 11:00

sql sum group by用法(**L 求和语句就是GROUP by的sum,在线等)

sql sum group by用法(**L 求和语句就是GROUP by的sum,在线等)

大家好,今天小编来为大家解答以下的问题,关于sql sum group by用法,**L 求和语句就是GROUP by的sum,在线等这个很多人还不知道,现在让我们一起来看看吧!

2026年4月27日 16:20

静态网页制作考题和答案(网页设计考题 高分!!!在线等!!!)

静态网页制作考题和答案(网页设计考题 高分!!!在线等!!!)

今天这份关于静态网页制作考题和答案的指南,将用80%的篇幅讲透网页设计考题 高分!!!在线等!!!这个决定成败的细节,绝对让你不虚此行。

2026年4月25日 08:40

格式工厂在线转换(jpg在线转换jpeg-如何将jpg图片格式改为jpeg)

格式工厂在线转换(jpg在线转换jpeg-如何将jpg图片格式改为jpeg)

你是否好奇,为什么人人都在谈格式工厂在线转换?它和jpg在线转换jpeg-如何将jpg图片格式改为jpeg之间究竟存在着怎样微妙的联系?答案就在下文。

2026年4月20日 19:40

站长工具2021最新国产(站长推荐在线)

站长工具2021最新国产(站长推荐在线)

本文旨在为您说清楚两件事:一是站长工具2021最新国产到底是什么,二是如何理解站长推荐在线。内容不长,但都是干货,希望能对您有所帮助。

2026年4月3日 22:00

免费在线crm(有没有免费的轻量级在线CRM系统可以分享一下)

免费在线crm(有没有免费的轻量级在线CRM系统可以分享一下)

下面,我们将通过免费在线crm的概述、有没有免费的轻量级在线CRM系统可以分享一下的详解以及总结展望三个部分,为您系统梳理这一主题。

2026年3月27日 15:20

更多文章:


setselected(android setselected用法以及)

setselected(android setselected用法以及)

前几天,一位朋友问我:setselected到底该怎么学?我只回了他三个字:抓住android setselected用法以及。今天就来详细说说为什么。

2026年4月29日 15:20

编程语言自学网站(大学超实用的8个编程语言学习网站)

编程语言自学网站(大学超实用的8个编程语言学习网站)

其实编程语言自学网站的问题并不复杂,但是又很多的朋友都不太了解大学超实用的8个编程语言学习网站,因此呢,今天小编就来为大家分享编程语言自学网站的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

2026年4月29日 15:00

springgateway路由配置(gateway网关配合nacos做动态路由)

springgateway路由配置(gateway网关配合nacos做动态路由)

本文是您理解springgateway路由配置的最后一站。我们将通过剖析gateway网关配合nacos做动态路由,帮你打通任督二脉,彻底领悟。

2026年4月29日 14:40

esp是什么意思英语教学(书上的esp是什么意思(有图))

esp是什么意思英语教学(书上的esp是什么意思(有图))

这篇文章给大家聊聊关于esp是什么意思英语教学,以及书上的esp是什么意思(有图)对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

2026年4月29日 14:20

虚拟机vim命令(虚拟机centos64位 在Vim中手动配置了ip成功保存后,不能显示)

虚拟机vim命令(虚拟机centos64位 在Vim中手动配置了ip成功保存后,不能显示)

曾几何时,我也觉得虚拟机vim命令高不可攀,尤其虚拟机centos64位 在Vim中手动配置了ip成功保存后,不能显示更是一头雾水。后来才发现,只是没找对方法,希望我的经验能帮到你。

2026年4月29日 14:00

php socket框架(请教php大神,php如何实现点击页面上的一个按钮发送socket的tcp数据)

php socket框架(请教php大神,php如何实现点击页面上的一个按钮发送socket的tcp数据)

本篇关于php socket框架的讲解,将摒弃陈词滥调,直击请教php大神,php如何实现点击页面上的一个按钮发送socket的tcp数据这一实战要害,给你可即刻应用的策略。

2026年4月29日 13:40

java设计简单的swing(java swing表格实例制作,简单两行两列,在线等)

java设计简单的swing(java swing表格实例制作,简单两行两列,在线等)

本文旨在解决您关于java设计简单的swing的两大困惑:一是理清基本概念,二是深入解析java swing表格实例制作,简单两行两列,在线等。内容干练,直奔主题。

2026年4月29日 13:20

如何制作svg图片(如何使用SVG生成超酷的页面预加载素描动画效果)

如何制作svg图片(如何使用SVG生成超酷的页面预加载素描动画效果)

想知道那些精通如何制作svg图片的人,是如何看待如何使用SVG生成超酷的页面预加载素描动画效果的吗?本篇将为你揭秘他们的思考路径。

2026年4月29日 13:00

qq烟花特效(QQ能不能出现烟花特效)

qq烟花特效(QQ能不能出现烟花特效)

大家好,关于qq烟花特效很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于QQ能不能出现烟花特效的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

2026年4月29日 12:40

git push到远程分支(Git怎么推送本地分支到远程新分支上面去)

git push到远程分支(Git怎么推送本地分支到远程新分支上面去)

上一篇文章我们介绍了git push到远程分支的基础,今天我们将深入其核心环节——Git怎么推送本地分支到远程新分支上面去,看看它如何承前启后。

2026年4月29日 12:20

最近更新

setselected(android setselected用法以及)
2026-04-29 15:20:02 浏览:0
springgateway路由配置(gateway网关配合nacos做动态路由)
2026-04-29 14:40:02 浏览:0
qq烟花特效(QQ能不能出现烟花特效)
2026-04-29 12:40:02 浏览:0
热门文章

mysql insert into字段顺序问题(mysql insert into的问题)
2026-04-13 16:00:02 浏览:1
split函数 sql(求sql split函数的用法)
2026-03-26 20:40:01 浏览:1
标签列表