package com.sust.farmhousemanage;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.*;
import java.sql.*;
/**
* @author 25868
*/
public class ShowFarmHouseInfoFrame extends JFrame {
FarmHouse fh = new FarmHouse();
JTextArea fhInfoListJTA = null;
//对输出进行处理
public StringBuffer setStringLen(int len) {
StringBuffer string = new StringBuffer();
for(int i = 0; i < 70-len; i++) {
string.append(" ");
}
return string;
}
/**
* 显示所有农家乐信息
*/
public void showAllStuInfo(){
fhInfoListJTA.setText("");
List<FarmHouse> list = fh.queryAllStuInfo();
for(FarmHouse farmhouse:list) {
String name = farmhouse.getfhName();
String addr = farmhouse.getfhAddr();
String pername = farmhouse.getfhPername();
String pertel = farmhouse.getfhPertel();
fhInfoListJTA.setText(fhInfoListJTA.getText()
+name + setStringLen(name.getBytes().length).toString()
+ addr + setStringLen(addr.getBytes().length).toString()
+ pername + setStringLen(pername.getBytes().length).toString()
+ pertel + "\n");
}
}
/**
* 构造函数
*/
public ShowFarmHouseInfoFrame() {
this.setSize(1000, 600);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
//界面标题部分
JLabel titleJL = new JLabel("农家乐信息管理系统");
Font font = new Font("微软雅黑", 1, 20);
titleJL.setFont(font);
titleJL.setLayout(null);
titleJL.setBounds(400, 10, 200, 20);
//按钮部分
JPanel buttonJP = new JPanel();
buttonJP.setLayout(null);
buttonJP.setBackground(Color.blue);
buttonJP.setBounds(0, 50, 1000, 40);
JButton jbAdd = new JButton("添加农家乐信息");
jbAdd.setBounds(0, 10, 175, 30);
jbAdd.setBackground(Color.green);
JButton jbDelete = new JButton("删除农家乐信息");
jbDelete.setBounds(275, 10, 175, 30);
jbDelete.setBackground(Color.green);
JButton jbModify = new JButton("修改农家乐信息");
jbModify.setBounds(550, 10, 175, 30);
jbModify.setBackground(Color.green);
JButton jbQuery = new JButton("查询农家乐信息");
jbQuery.setBounds(825, 10, 175, 30);
jbQuery.setBackground(Color.green);
//buttonJP.setLayout(new FlowLayout());
buttonJP.add(jbAdd);
buttonJP.add(jbDelete);
buttonJP.add(jbModify);
buttonJP.add(jbQuery);
JPanel listHeadJP = new JPanel();
listHeadJP.setBackground(Color.white);
listHeadJP.setLayout(null);
listHeadJP.setBounds(0, 120, 1000, 30);
JLabel nameHeadJL = new JLabel(" 名 字");
nameHeadJL.setBackground(Color.gray);
nameHeadJL.setBounds(50, 0, 175, 25);
JLabel addrHeadJL = new JLabel(" 地 址");
addrHeadJL.setBackground(Color.gray);
addrHeadJL.setBounds(325, 0, 175, 25);
JLabel pernameHeadJL = new JLabel("负责人");
pernameHeadJL.setBackground(Color.gray);
pernameHeadJL.setBounds(590, 0, 175, 25);
JLabel pertelHeadJL = new JLabel(" 电 话");
pertelHeadJL.setBackground(Color.gray);
pertelHeadJL.setBounds(875, 0, 175, 25);
listHeadJP.add(nameHeadJL);
listHeadJP.add(addrHeadJL);
listHeadJP.add(pernameHeadJL);
listHeadJP.add(pertelHeadJL);
Font fhInfoListFont = new Font("微软雅黑", 0, 13);
fhInfoListJTA = new JTextArea(20,20);
fhInfoListJTA.setBounds(10, 152, 1000, 400);
fhInfoListJTA.setBorder (BorderFactory.createEmptyBorder (1,1,1,5));
fhInfoListJTA.setColumns (20);
fhInfoListJTA.setRows (20);//相当于设置文本区组件的初始大小,并不是说一行只能写0
fhInfoListJTA.setFont(fhInfoListFont);
this.add(titleJL);
this.add(buttonJP);
this.add(listHeadJP);
this.add(fhInfoListJTA);
showAllStuInfo();
this.setVisible(true);
//添加农家乐信息
jbAdd.addMouseListener(new MouseAdapter(){
//匿名内部类使用方法的临时变量需要提前,负责会让你改为final,改为final是为了延长变量的声明周期
JTextField numJTF = null;
JTextField nameJTF = null;
JTextField classJTF = null;
JTextField professionalJTF = null;
@Override
public void mouseClicked(MouseEvent e) {
final JFrame addJF = new JFrame();
addJF.setSize(310, 300);
addJF.setBackground(Color.gray);
addJF.setLocationRelativeTo(null);
addJF.setVisible(true);
addJF.setLayout(new FlowLayout());
JLabel numJL = new JLabel("名 字:");
numJTF = new JTextField(20);
JLabel nameJL = new JLabel("地 址:");
nameJTF = new JTextField(20);
JLabel classJL = new JLabel("负责人:");
classJTF = new JTextField(20);
JLabel professionalJL = new JLabel("电 话:");
professionalJTF = new JTextField(20);
//addJF.dispose();//销毁子窗口
addJF.add(numJL);
addJF.add(numJTF);
addJF.add(nameJL);
addJF.add(nameJTF);
addJF.add(classJL);
addJF.add(classJTF);
addJF.add(professionalJL);
addJF.add(professionalJTF);
JButton addJB = new JButton("添加");
addJF.add(addJB);
addJB.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String nameAdd = numJTF.getText();
String addrAdd = nameJTF.getText();
String pernameAdd = classJTF.getText();
String pertelAdd = professionalJTF.getText();
//输入的信息为空的处理
if(nameAdd == "" | addrAdd == "" | pernameAdd == "" | pertelAdd == "") {
JFrame tipJF = new JFrame("提示");
tipJF.setVisible(true);
tipJF.setSize(200,100);
tipJF.setLocationRelativeTo(null);
JLabel tipJL = new JLabel("请填入了所有的信息之后再点击提交");
tipJF.add(tipJL);
}else {
fh = new FarmHouse();
fh.addStuInfo(nameAdd, addrAdd, pernameAdd, pertelAdd);
addJF.dispose();
JFrame addSuccessfulJF = new JFrame("提示");
addSuccessfulJF.setLocationRelativeTo(null);
addSuccessfulJF.setSize(260, 100);
addSuccessfulJF.setVisible(true);
addSuccessfulJF.setLayout(new FlowLayout());
JLabel SuccessfulJL = new JLabel("添加农家乐信息成功!");
addSuccessfulJF.add(SuccessfulJL);
}
}
});
}
});
//删除农家乐信息
jbDelete.addMouseListener(new MouseAdapter() {
「已注销」
- 粉丝: 12
- 资源: 1
最新资源
- 基于Python+ Dijkstra 算法的最短路径规划
- 上机六 Java UI设计及图形功能.mhtml
- 毕设-ssm的最多跑一次微信小程序-源码-LW-PPT.rar
- 圣诞树网页HTML代码,这个版本包含了更多的交互性和动态效果
- 基于 Python 控制台的动态规划 0-1 背包问题 的课程设计作业程序实现
- 矩阵与线程的对应关系图
- location-cleaned16.7驱动
- 机器学习(预测模型):用户对ChatGPT(一个人工智能聊天机器人)的评价和反馈数据集
- int201 Decision Computation and Language xjtlu 复习笔记
- GEMM优化代码实现1-1PPT
- 操作系统课设-虚拟文件系统模拟-基于java实现
- AMGA 算法是基于微生物群体群落的演化过程而来的一类元启发式算法,其核心思想是借鉴微生 物在进化过程中的竞争、合作、交流等行为特征,对问题进行求解 AMGA 算法的主要特点包括 了:1)
- 机器学习(预测模型):地震检波器数据集
- 计算机专业学习和职业指南
- 基于Python+socket的聊天管理系统
- 蓝桥杯嵌入式-主板或主板+拓展板测试
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈