👨💻个人主页:@元宇宙-秩沅
**hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!**
本文由 秩沅 原创
收录于专栏 玩归玩闹归闹,别拿java开玩笑
——————————————————
⭐相关文章⭐
——————————————————
@[TOC]
用户主界面功能的设计和实现
👨💻主界面效果图
首先主界面中实现用户可以点击美食,医疗,购物,景点,娱乐及住宿功能按钮还有导航的功能按键,提供搜索建议框与本应用中的动态列表选项,还有设置按钮。效果图如图所示。
主界面的设计主要时以下三个方法,分别为构造函数 SystemGUI()进行登录界面主面板的创建和其他方法的调用,setgounp() 方法进行主界面GUI设计和布局美化,添加六个功能按键,常德文字介绍,搜索框,设置,背景图片等组件的布局设计,使用SQLmess()方法进行数据库的连接,在主页上显示用户的昵称,体现程序的友好性
参考代码:
private void setgounp() {
//设置主面板的布局和美观
setTitle("一站知常德");
setBounds(300,100,1000,550);
setResizable(false); //禁止最大化
//setLocationRelativeTo(null); 居中
//设置布局
JPanel MJPanel ;
MJPanel = new JPanel();
MJPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK,15)); //设置一个带有颜色的边界和其宽度
setContentPane(MJPanel);
MJPanel.setLayout(null); //JPanel的默认布局--FollowLayout
//添加功能按钮
JButton food ,doctor ,shop ,view ,happy ,house ,buyhouse;
food = new JButton("美食");
doctor = new JButton("医疗");
shop = new JButton("购物");
view = new JButton("景点");
happy = new JButton("娱乐");
house = new JButton("住宿");
buyhouse = new JButton("订房信息查询");
//设置前景颜色(作用于字体)
food.setForeground(Color.BLACK);
doctor.setForeground(Color.BLACK);
shop.setForeground(Color.BLACK);
view.setForeground(Color.BLACK);
happy.setForeground(Color.BLACK);
house.setForeground(Color.BLACK);
buyhouse.setForeground(Color.BLACK);
//设置字体样式
food.setFont(new Font(selfFont,Font.BOLD, 18));
doctor.setFont(new Font(selfFont,Font.BOLD, 18));
shop.setFont(new Font(selfFont,Font.BOLD, 18));
view.setFont(new Font(selfFont,Font.BOLD, 18));
happy.setFont(new Font(selfFont,Font.BOLD, 18));
house.setFont(new Font(selfFont,Font.BOLD, 18));
buyhouse.setFont(new Font(selfFont,Font.BOLD, 18));
food.setBackground(Color.WHITE);//设置背景颜色
doctor.setBackground(Color.WHITE);
shop.setBackground(Color.WHITE);
view.setBackground(Color.WHITE);
happy.setBackground(Color.WHITE);
house.setBackground(Color.WHITE);
buyhouse.setBackground(Color.WHITE);
food.setBounds(50,150, 90,30);//设置位置
doctor.setBounds(200,150, 90,30);
shop.setBounds(350,150, 90,30);
view.setBounds(500,150, 90,30);
happy.setBounds(650,150, 90,30);
house.setBounds(800,150, 90,30);
buyhouse.setBounds(800,50, 130,30);
food.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));//边界美观
doctor.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
shop.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
view.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
happy.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
house.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
buyhouse.setBorder(BorderFactory.createLineBorder(Color.BLACK,4));
MJPanel.add(food);
MJPanel.add(doctor);
MJPanel.add(shop);
MJPanel.add(view);
MJPanel.add(happy);
MJPanel.add(house);
MJPanel.add(buyhouse);
//添加设置功能
JButton Setbutton ;
Setbutton = new JButton("设置");
Setbutton.setForeground(Color.BLACK); //设置前景色
Setbutton.setFont(new Font(selfFont,Font.BOLD, 18)); //设置字体
Setbutton.setBackground(Color.WHITE); //设置背景色
Setbutton.setBorder(BorderFactory.createLineBorder(Color.BLACK,2)); //设置边界色和大小
Setbutton.setBounds(880,460, 50,30); //设置布局位置
MJPanel.add(Setbutton);
👨💻界面六大功能按钮
当用户点击六大功能按钮后,如图4.7所示。进入相应功能的界面,下面举例以点击了娱乐按钮进入的界面,如图4.8所示,每个大功能,点击后都会有相应的小功能界面,点击小功能界面的按钮后会出现该功能的相关领域信息的图文浏览,每个界面都可按返回键按钮,如图4.9所示。
参考代码:
六大功能按键的设计主要实现接口鼠标监听事件,来实现以下几个方法,分别用Doctor(),Food(),Happy(),House(), Shop(), View()六个方法来实现医疗,美食,娱乐,住房,购物,风景六个模块的设计,每个模块主要是以JButton,JAreaText,JLabel等来进行文本,图片,按钮等组件的添加,而Back(JPanel Mpanel ,JFrame a )方法,则是每个功能界面必备的,作用是返回上一级,随及关闭当前窗口。
//按下“美食”按钮时调用
public void Food()
{
//增加主面板
JFrame sonPanel = new JFrame() ;
JPanel JPAction = new JPanel();
sonPanel.setTitle("常德美食");
sonPanel.setBounds(300,100,1000,550);
sonPanel.setContentPane(JPAction);
JPAction.setBorder(BorderFactory.createLineBorder(Color.BLACK,15)); //设置一个带有颜色的边界和其宽度
JPAction.setLayout(null); //JPanel的默认布局--FollowLayout
//sonPanel.setResizable(false); //禁止最大化
sonPanel.setVisible(true);
sonPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//制作美食界面
JTextField DFood = new JTextField(40); //美食榜单文字
DFood.setText("|常德特色美食榜单|");
DFood.setFont(new Font(selfFont,Font.BOLD, 80));
DFood.setBounds(110,200, 800,200);
DFood.setOpaque(false);
DFood.setEditable(false);
JPAction.add(DFood);
JButton food1 ,food2 ,food3 ,food4,food5 ,food6; //制作美食榜单的功能按钮
food1 = new JButton("常德米粉");
food2 = new JButton("常德酱板鸭");
food3 = new JButton("常德钵子菜");
food4 = new JButton("常德豆皮");
food5 = new JButton("常德药膳扒鸡");
food6 = new JButton("北堤麻辣肉");
//设置前景颜色(作用于字体)
food1.setForeground(Color.WHITE);
food2.setForeground(Color.WHITE);
food3.setForeground(Color.WHITE);
food4.setForeground(Color.WHITE);
food5.setForeground(Color.WHITE);
food6.setForeground(Color.WHITE);
//设置字体样式
food1.setFont(new Font(selfFont,Font.BOLD, 18));
food2.setFont(new Font(selfFont,Font.BOLD, 18));
food3.setFont(new Font(selfFont,Font.BOLD, 18));
food4.setFont(new Font(selfFont,Font.BOLD, 18));
food5.setFont(new Font(selfFont,Font.BOLD, 18));
food6.setFont(new Font(selfFont,Font.BOLD, 18));
food1.setBackground(Color.black);//设置背景颜色
food2.setBackground(Color.black);
food3.setBackground(Color.black);
food4.setBackground(Color.black);
food5.setBackground(Color.black);
food6.setBackground(Color.black);
food1.setBounds(50 ,100, 110,30);//设置位置
food2.setBounds(200,100, 110,30);
food3.setBounds(350,100, 110,30);
food4.setBounds(500,100, 110,30);
food5.setBounds(650,100, 110,30);
food6.setBounds(800,100, 110,30);
food1.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));//边界美观
food2.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
food3.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
food4.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
food5.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
food6.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
JPAction.add(food1);
JPAction.add(food2);
JPAction.add(food3);
JPAction.add(food4);
JPAction.add(food5);
JPAction.add(food6);
//插入背景图
ImageIcon backgruonp ;
JLabel image ;
backgruonp = new ImageIcon("美食背景.png");
image = new JLabel(backgruonp);
image.setBounds(15,15,956,483);
JPAction.add(image);
Back(JPAction,sonPanel);
//点击第一个美食按钮
food1.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
//点击按钮后可显示视图信息
if(e.getSource() == food1 && e.getButton() == MouseEvent.BUTTON1 )//当按下按钮时
{
food1();
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
});
//点击第二个美食按钮
food2.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
//点击按钮后可显示视图信息
if(e.getSource() == food2 && e.getButton() == MouseEvent.BUTTON1 )//当按下按钮时
{
food2();
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
});
👨💻界面搜素建议框和导航功能
当用户想要看到推荐点时,搜索建议框和动态列表功能即显现出来,下拉列表,选中后,点击导航按钮,即可跳转相应界面
代码参考:
登录界面功能用以下三个方法,分别为构造函数 GUI()进行登录界面主面板的创建,mainpanel()方法进行登录界面GUI设计和布局美化,induage()方法,进行数据库的连接,并判断用户输入的账号密码是否与数据库中的一致。注册信息界面方法表如下表4.2所示。
//主面板的创建
public GUI ()
{
mainpanel();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void mainpanel()
{
//设置主面板的布局和美观
setTitle("一站知常德");
setBounds(300,100,1000,550);
setResizable(false); //禁止最大化
//setLocationRelativeTo(null); //居中
//设置布局
JPanel MJPanel ;
MJPanel = new JPanel();
MJPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK,15)); //设置一个带有颜色的边界和其宽度
setContentPane(MJPanel);
MJPanel.setLayout(null); //JPanel的默认布局--FollowLayout
//设置账号密码标签
JLabel ANumber , PNumber;
Font bold = new Font("华文琥珀",Font.BOLD,25);
ANumber = new JLabel("账号");
PNumber = new JLabel("密码");
ANumber.setFont(bold); //设置字体
PNumber.setFont(bold); //设置字体
ANumber.setBounds(351, 300, 91, 50);
PNumber.setBounds(351, 360, 91, 50);
// ANumber .setOpaque(false);
// PNumber .setOpaque(false);
MJPanel.add(ANumber);
MJPanel.add(PNumber);
//设置输入框
ANField = new JTextField(20);
PNField = new JPasswordField(20);
ANField.setBounds(420, 315, 150, 25);
PNField.setBounds(420, 375, 150, 25);
//ANField.setText("请输入账号");
//PNField.setText("请输入密码");
MJPanel.add(ANField);
MJPanel.add(PNField);
//设置登录和注册按钮
JButton record,register;
record = new JButton("登录");
register = new JButton("注册");
record.setForeground(Color.BLACK); //设置前景颜色(作用于字体)
register.setForeground(Color.BLACK);
record.setFont(new Font("仿宋", Font.BOLD, 12));
register.setFont(new Font("仿宋", Font.BOLD, 12));
record.setBackground(Color.gray); //设置背景颜色
register.setBackground(Color.gray);
record.setBounds(380,420,70,30);
register.setBounds(490,420,70,30);
MJPanel.add(record);
MJPanel.add(register);
//插入背景图
ImageIcon backgruonp ;
JLabel image ;
backgruonp = new ImageIcon("常德风景图片.png");
image = new JLabel(backgruonp);
image.setBounds(15,15,956,483);
MJPanel.add(image);
//设置注册信息跳转界面
register.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
//单击注册按钮
if(e.getSource() == register && e.getButton() == MouseEvent.BUTTON1 )
{
SQL restore = new SQL();
restore.setVisible(true);
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
});
//设置登录信息跳转界面
record.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
//单击登录按钮
if(e.getSource() == record && e.getButton() == MouseEvent.BUTTON1 )
{
if( induage() == true)
{
@SuppressWarnings("unused")
SystemGUI mainGUI = new SystemGUI(ANField.getText()); //将账户作为参数传递
dispose();
}
else
{
//增加提示窗口
JFrame inform = new JFrame();
inform.setTitle("提示");
inform.setBounds(640, 305, 280,100);
JLabel occ = new JLabel("账户或密码错误,请重新输入!");
occ.setFont(new Font("华文行楷",Font.BOLD,18));
inform.add(occ);
setResizable(true); //禁止最大化
inform.setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
});
}
@SuppressWarnings("deprecation")
public boolean induage(){
//连接数据库核实信息
boolean duage = false ;
Connection nect = null;
ResultSet answar = null ;
try
{
//首先连接数据库
String a ="jdbc:mysql://localhost/CMession?"+"useSSL = true & serverTimezone = GMT &characterEncoding = utf-8 ";
nect = DriverManager.getConnection(a,"root","l20011223");
System.out.println("连接成功");
}
catch (SQLException e1) {
e1.printStackTrace();}
Statement sql = null;
try {
sql = nect.createStatement(); //声明数据库
String query =" select password from passCard where acount= '"+ANField.getText() +"';";
//通过账号查找密码
answar = sql.executeQuery(query);
while(answar.next())
{
System.out.println(answar.getString(1)+" "+PNField.getText());
if(answar.getString(1).equals(PNField.getText()) ) //判断密码是否相等
{
duage = true ;
}
}
} catch (SQLException e1) {
e1.printStackTrace(); }
try {
nect.close();
System.out.println("已关闭连接");
} catch (SQLException e1){
e1.printStackTrace();}
//dispose();
return duage;
}
}
👨💻界面在线订房功能
当用户想要看到推荐点时,搜索建议框和动态列表功能即显现出来,下拉列表,选中后,点击导航按钮,即可跳转相应界面。
若用户输入正确时则会成功进入主界面,进行相关功能操作,效果图如下图5.2所示。
当用户进入到注册界面时,需要填写注册信息,如果注册信息未填满或者密码长度不足六位数字则会弹出以下窗口提示,效果图如下图5.3所示。
若用户注册时,注册的账号是重复的,亦会有如下提示出现,提示重新注册,效果图如下图5.4所示。
代码参考:
//添加导航框
listData = new String[]{
"推荐景点:柳叶湖", "推荐娱乐:欢乐水世界", "推荐美食:常德酱板鸭", "推荐医院:常德市第一人民医院"};
find = new JComboBox<String>(listData); // 创建一个下拉列表框
sreach = new JButton("导航");
sreach.setFont(new Font(selfFont,Font.BOLD, 20));
find.setBounds(280,50,300,40);
sreach.setBounds(600,50,80,40);
// 添加条目选中状态改变的监听器
sreach.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
if(e.getSource() == sreach && e.getButton() == MouseEvent.BUTTON1 )//当按下导航按钮时
{
if(find.getSelectedIndex() == 0 ) view1();
else if(find.getSelectedIndex() == 1 ) happy1();
else if(find.getSelectedIndex() == 2 ) food2();
else if(find.getSelectedIndex() == 3 ) doctor1();
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
MJPanel.add(find);
MJPanel.add(sreach);
👨💻界面设置功能
用户点击设置按钮后可以看到设置中的三个功能分别为设置字体,使用帮助和关于软件。按返回或者关闭按钮可将窗口关闭如图4.12所示。三大功能界面如图4.13,图4.14,图4.15所示。
相关代码
实现设置三个的功能首先在Set1()方法中关键用JcomboBox创建下拉列表,以提前设置好的全局变量字体字符串为传导,进行全局字体设置。而set2()和set3()方法则是直接在面板中引入文本框,每个窗口可按Back(JPanel Mpanel ,JFrame a )方法实现的返回按键,进行上一界面的返回,并关闭当前界面,如表4.5所示。
public void set1()
{
//创建窗口
JFrame sonPanel = new JFrame() ;
JPanel JPAction = new JPanel();
sonPanel.setTitle("设置字体");
sonPanel.setBounds(1000,270,240,320);
sonPanel.setContentPane(JPAction);
JPAction.setBorder(BorderFactory.createLineBorder(Color.BLACK,16)); //设置一个带有颜色的边界和其宽度
JPAction.setLayout(null); //JPanel的默认布局--FollowLayout
sonPanel.setResizable(false); //禁止最大化
sonPanel.setVisible(true);
sonPanel.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Back(JPAction, sonPanel); //返回按钮
//下拉列表创建
String[] list;
JButton sreach1 ;
JComboBox<String> find1 ;
list = new String[]{
"华文行楷", "华文琥珀", "宋体", "黑体"};
find1 = new JComboBox<String>(list); // 创建一个下拉列表框
sreach1 = new JButton("确认修改");
sreach1.setFont(new Font(selfFont,Font.BOLD, 20));
find1.setBounds(50,60, 90,30);
sreach1.setBounds(40,180, 120,40);
// 添加条目选中状态改变的监听器
sreach1.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
if(e.getSource() == sreach1 && e.getButton() == MouseEvent.BUTTON1 )//当按下导航按钮时
{
if(find1.getSelectedIndex() == 0 ) selfFont ="华文行楷";
else if(find1.getSelectedIndex() == 1 ) selfFont ="华文琥珀";
else if(find1.getSelectedIndex() == 2 ) selfFont ="宋体";
else if(find1.getSelectedIndex() == 3 ) selfFont ="黑体";
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
JPAction.add(find1);
JPAction.add(sreach1);
}
public void set2()
{
//创建窗口
JFrame sonPanel = new JFrame() ;
JPanel JPAction = new JPanel();
sonPanel.setTitle("使用帮助");
sonPanel.setBounds(1000,270,240,320);
sonPanel.setContentPane(JPAction);
JPAction.setBorder(BorderFactory.createLineBorder(Color.BLACK,16)); //设置一个带有颜色的边界和其宽度
JPAction.setLayout(null); //JPanel的默认布局--FollowLayout
sonPanel.setResizable(false); //禁止最大化
sonPanel.setVisible(true);
sonPanel.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Back(JPAction, sonPanel); //返回按钮
//文本区创建
JTextArea help = new JTextArea(50,50);
help.setBounds(20,50,190,210);
help.setText(" \n本系统是常德旅游信息系统\n\n 进入界面后,直接点击您\n\n看到的按钮进行操作即可\n\n若有疑问请联系\n\nQQ:2415812312");
help.setFont(new Font(selfFont,Font.BOLD,15));
//help.setOpaque(false); //设置为透明
help.setEditable(false); //将文本区设置为不可编辑
JPAction.add(help);
}
public void set3()
{
//创建窗口
JFrame sonPanel = new JFrame() ;
JPanel JPAction = new JPanel();
sonPanel.setTitle("关于软件");
sonPanel.setBounds(1000,270,240,320);
sonPanel.setContentPane(JPAction);
JPAction.setBorder(BorderFactory.createLineBorder(Color.BLACK,16)); //设置一个带有颜色的边界和其宽度
JPAction.setLayout(null); //JPanel的默认布局--FollowLayout
sonPanel.setResizable(false); //禁止最大化
sonPanel.setVisible(true);
sonPanel.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Back(JPAction, sonPanel); //返回按钮
//文本区创建
JTextArea help = new JTextArea(50,50);
help.setBounds(20,50,180,210);
help.setText(" \n本GUI系统由 秩沅 创建\n\n采用JavaGUI各个API创建\n\n包含数据库连接\n\n信息存储查询\n\n界面美化");
help.setFont(new Font(selfFont,Font.BOLD,15));
//help.setOpaque(false); //设置为透明
help.setEditable(false); //将文本区设置为不可编辑
JPAction.add(help);
}
👨💻界面住房信息查询功能
用户在主页点击住房信息查询按钮时,可进入住房信息查询界面,每个文本框中显示的信息都是从存储信息的数据库中导入,以账号作为主键导入对于的昵称,账户号和订房信息,供游客浏览
相关代码:
//住房信息查询
public void buyHouse()
{
JFrame sonPanel = new JFrame() ;
JPanel JPAction = new JPanel();
sonPanel.setTitle("住房信息个人中心");
sonPanel.setBounds(300,100,1000,550);
sonPanel.setContentPane(JPAction);
JPAction.setBorder(BorderFactory.createLineBorder(Color.BLACK,15)); //设置一个带有颜色的边界和其宽度
JPAction.setLayout(null); //JPanel的默认布局--FollowLayout
sonPanel.setResizable(false); //禁止最大化
sonPanel.setVisible(true);
sonPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
JLabel l1 = new JLabel("昵称:");
JLabel l2 = new JLabel("账户:");
JLabel l3 = new JLabel("订房信息:");
JLabel l4 = new JLabel("欢迎入住常德,祝您居住愉快!");
l1.setFont(new Font(selfFont,Font.BOLD,23));
l2.setFont(new Font(selfFont,Font.BOLD,23));
l3.setFont(new Font(selfFont,Font.BOLD,23));
l4.setFont(new Font(selfFont,Font.BOLD,40));
l1.setBounds(290,150, 120,50);
l2.setBounds(290,210, 120,50);
l3.setBounds(240,270, 120,50);
l4.setBounds(250,30, 600,50);
JTextField x1 = new JTextField(8);
JTextField x2 = new JTextField(8);
JTextField x3 = new JTextField(8);
x1.setBounds(350,160,400,30);
x2.setBounds(350,220,400,30);
x3.setBounds(350,280,400,30);
SQLmess();
//从数据库中导入信息
x1.setText(SQLmess());
x2.setText(Acount);
x3.setText(SQLmess2());
x1.setFont(new Font("华文琥珀",Font.BOLD,20));
x2.setFont(new Font("华文琥珀",Font.BOLD,20));
x3.setFont(new Font("华文琥珀",Font.BOLD,20));
System.out.println(huoseMess);
if(huoseMess != null) UpdataSQLmess();
JPAction.add(l1);
JPAction.add(l2);
JPAction.add(l3);
JPAction.add(l4);
JPAction.add(x1);
JPAction.add(x2);
JPAction.add(x3);
//插入背景图
ImageIcon backgruonp ;
JLabel image ;
backgruonp = new ImageIcon("主页背景1.png");
image = new JLabel(backgruonp);
image.setBounds(15,15,956,483);
JPAction.add(image);
Back(JPAction, sonPanel);
}
👨💻常用API
1.设置边框
setBorder
MJPanel.setBorder(new LineBorder(new Color(0, 255, 0)));
2.禁止窗口最大化
setResizable(false);
3.窗口将置于屏幕的中央。
setLocationRelativeTo(null); //居中
4.添加面板
setContentPane(MJPanel);
5,设置字体
xx.setFont(new Font("华文琥珀",Font.BOLD,30));
xx.setBounds(49, 170, 91, 38);
二者要配套使用,不然显示不出
6,设置不透明
xx.setOpaque();
防止被覆盖
监听:
2.getSelectedIndex() 返回下拉表格的序号
3.getSelectedItem() 返回下拉表格的名字
你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!