📄 mainframe.java
字号:
txt1id.setVisible(true);
pwd1.setVisible(true);
btn1login.setVisible(true);
btn1no.setVisible(true);
lbl1prvMeg.setVisible(false);
lbl1Reg.setVisible(true);
lbl1out.setVisible(false);
jPanel2.setVisible(false);
jPanel3.setVisible(false);
txtmNum.setText("");
cbxmId.removeAllItems();
btn1send.setVisible(true);
btn1cancle.setVisible(true);
cbxgetname.setVisible(true);
cbxgetname.removeAllItems();
//隐藏留言内容
jScrollPane1.setVisible(false);
txt1display.setVisible(false);
//显示发送留言内容
jScrollPane2.setVisible(true);
txt1send.setVisible(true);
txt1send.setText("");
lbl1sendto.setVisible(true);
lbl1send.setVisible(true);
//隐藏个人资料
lbl1Data.setVisible(false);
//留言-发言区锁定
txt1send.setEditable(false);
//留言-发送键锁定
btn1send.setEnabled(false);
//留言-取消键锁定
btn1cancle.setEnabled(false);
//留言-对象锁定
cbxgetname.setEnabled(false);
select();
}
}
/*发送留言事件*/
public void btn1send_actionPerformed(ActionEvent e) {
//判断留言内容是否为空
if (txt1send.getText().trim().equals("")) {
JOptionPane.showMessageDialog(this, "不能发送空的留言");
//判断留言内容是否符合要求
} else if (txt1send.getText().trim().length() > 50) {
JOptionPane.showMessageDialog(this, "对不起,留言最多50字!");
//---判断留言是是否是公共的,将信息插入到PubMeg表中;
} else if (cbxgetname.getSelectedItem().equals("大家")) {
txt1display.setText("");
//得到当前时间
String d1 = this.TestTime();
String sql1 = "insert into PubMeg values('" + txt1id.getText() +
"','" + d1 + "','" + txt1send.getText().trim() + "')";
db.ResultSql(sql1);
//调用自定义查询公共留言方法
select();
txt1send.setText(null);
cbxgetname.setSelectedIndex(0);
// ------个人留言,将信息插入到PrvMeg 表中,并修改StuMeg表中的是否有留言状态字段;
} else {
//得到当前时间
String d2 = this.TestTime();
String sql2 = "insert into PrvMeg values('" + txt1id.getText() +
"','" + cbxgetname.getSelectedItem() + "','" + d2 +
"','" + txt1send.getText().trim() + "')";
db.ResultSql(sql2);
String sql3 =
"update stuMeg set sstau=1 where id = '" +
cbxgetname.getSelectedItem() + "'";
db.ResultSql(sql3);
txt1send.setText(null);
cbxgetname.setSelectedIndex(0);
JOptionPane.showMessageDialog(this, "发送成功");
}
}
/*重置事件*/
public void btn1cancle_actionPerformed(ActionEvent e) {
txt1send.setText(null);
cbxgetname.setSelectedIndex(0);
}
/*下一页事件*/
public void lbl1next_mouseClicked(MouseEvent e) {
try {
if (lbl1wel.getText().equals("你还没有登陆!")) {
JOptionPane.showMessageDialog(this, "请先登陆!");
//判断 ResultSet 对象是否指向最后一行,证明是否已到最后一页
} else if (txt1display.getText().equals("") || rs.isLast() ||
rs.isAfterLast()) {
JOptionPane.showMessageDialog(this, "已到最后一页");
} else {
//首先把 txt1display 置空
txt1display.setText(null);
int count = 0; //每页显示留言条数的计算器
while (rs.next()) {
txt1display.append("ID:"+rs.getString(1)+" " + rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (rs.isLast()) {
rs.last(); // 将指针移动到此 ResultSet 对象的最后一行
break;
}
if (count == 5)
break;
}
}
} catch (Exception ex) {
}
}
/*上一页事件*/
public void lbl1for_mouseClicked(MouseEvent e) {
try {
if (lbl1wel.getText().equals("你还没有登陆!")) {
JOptionPane.showMessageDialog(this, "请先登陆!");
//判断 ResultSet 对象是否指向前 5 条记录
} else if (rs == null || rs.getRow() <= 5) {
JOptionPane.showMessageDialog(this, "已到第一页");
} else {
int total = rs.getRow(); //获取 ResultSet 对象指针的位置
int num = total % 5;
int count; //每页显示留言条数的计算器
int temp;
/*判断 ResultSet 对象是否指向最后 && 行数除 5 取余 != 0*/
if (rs.isLast() && num != 0) {
count = 0;
temp = 0;
txt1display.setText(null);
/* while 是把指针指向上一页显示的 ResultSet 对象第一个*/
while (temp < num + 5) {
rs.previous(); //指针移动到此 ResultSet 对象的上一行
temp++;
}
// while 是把上一页的数据显示出来
while (rs.next()) {
txt1display.append("ID:"+rs.getString(1)+" " + rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (count == 5)
break;
}
} else {
txt1display.setText(null);
count = 0;
temp = 0;
/* while 是把指针指向上一页显示的 ResultSet 对象第一个*/
while (temp < 10) {
rs.previous(); //指针移动到此 ResultSet 对象的上一行
temp++;
}
// while 是把上一页的数据显示出来
while (rs.next()) {
txt1display.append("ID:"+rs.getString(1)+" " + rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (count == 5)
break;
}
}
}
} catch (Exception ex) {
}
}
/*首页事件*/
public void lbl1fir_mouseClicked(MouseEvent e) {
try {
if (lbl1wel.getText().equals("你还没有登陆!")) {
JOptionPane.showMessageDialog(this, "请先登陆!");
//判断 ResultSet 对象是否指向前 5 条记录
} else if (rs == null || rs.getRow() <= 5) {
JOptionPane.showMessageDialog(this, "已到第一页");
} else {
rs.beforeFirst(); // 指针移动到此 ResultSet 对象的开头
int count = 0; //每页显示留言条数的计算器
txt1display.setText(null);
while (rs.next()) {
txt1display.append("ID:" + rs.getString(1) + " " +
rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (count == 5)
break;
}
}
} catch (Exception ex) {
}
}
/*末页事件*/
public void lbl1last_mouseClicked(MouseEvent e) {
try {
if (lbl1wel.getText().equals("你还没有登陆!")) {
JOptionPane.showMessageDialog(this, "请先登陆!");
//判断 ResultSet 对象是否指向最后一行,证明是否已到最后一页
} else if (txt1display.getText().equals("") || rs.isLast() ||
rs.isAfterLast()) {
JOptionPane.showMessageDialog(this, "已到最后一页");
} else {
rs.last(); // 将指针移动到此 ResultSet 对象的最后一行
int total = rs.getRow(); //获取 ResultSet 对象的当前行
int num = total % 5;
int count = 0;
txt1display.setText(null);
if (num != 0) {
while (num != 0) {
rs.previous(); //指针移动到此 ResultSet 对象的上一行
num--;
} while (rs.next()) {
txt1display.append("ID:"+rs.getString(1)+" " + rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (count == 5)
break;
}
} else {
int temp = 5;
while (temp != 0) {
rs.previous(); //指针移动到此 ResultSet 对象的上一行
temp--;
} while (rs.next()) {
txt1display.append(" "+rs.getString(1)+" " + rs.getString(2) + " " +
rs.getString(3) + "\n");
txt1display.append("内容:" + rs.getString(4) + "\n\n");
count++;
if (count == 5)
break;
}
}
}
rs.last(); // 将指针移动到此 ResultSet 对象的最后一行
} catch (Exception ex) {
}
}
/*登陆处的退出事件*/
public void btn1no_actionPerformed(ActionEvent e) {
int faly= JOptionPane.showConfirmDialog(this,"您确认要退出吗?","确认",JOptionPane.YES_NO_OPTION);
if(faly==0){
this.dispose();
player.stop();
}
}
/*右键的帮助事件*/
public void milHelp_actionPerformed(ActionEvent e) {
Runtime rt = Runtime.getRuntime();
try {
rt.exec("hh.exe help.chm");
} catch (Exception ex) {
}
}
/*右键的关于事件*/
public void milAbout_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this, "北大青鸟(西安毕诚)A1Q6073 未定义小组制作", "关于我们",
1);
}
//窗口打开事件
public void this_windowOpened(WindowEvent e) {
Music();
select();
}
//个人资料事件
public void lbl1Data_mouseClicked(MouseEvent e) {
DataFrame df=new DataFrame(this);
df.setBounds(370, 180, 300, 400);
df.setVisible(true);
this.setEnabled(false);
}
/*管理事件*/
public void lbl1Admin_mouseClicked(MouseEvent e) {
try {
if (lbl1wel.getText().equals("你还没有登陆!")) {
JOptionPane.showMessageDialog(this, "请先登陆!");
} else if (!txt1id.getText().equals("admin")) {
JOptionPane.showMessageDialog(this, "您没有管理权限");
} else {
String value[] = {"留言管理", "学员管理"};
String Admin = (String) JOptionPane.showInputDialog(contentPane,
"请选择:",
"确认", JOptionPane.QUESTION_MESSAGE, null, value, value[1]);
if (Admin.equals("学员管理")) {
jPanel3.setVisible(false);
//显示发送留言内容区
jScrollPane2.setVisible(true);
txt1send.setVisible(true);
//留言-发送键显示
btn1send.setVisible(true);
//留言-取消键显示
btn1cancle.setVisible(true);
//留言To-对象显示
cbxgetname.setVisible(true);
//显示lbl
lbl1sendto.setVisible(true);
lbl1send.setVisible(true);
//得到学员信息
String sql="select * from stumeg";
ResultSet rsu=db.GetRs(sql);
rsu.last();
if(rsu.getRow()==1){
JOptionPane.showMessageDialog(this, "没有学员注册信息");
}else {
UserFrame uf = new UserFrame(this);
uf.setBounds(240, 180, 570, 347);
uf.setVisible(true);
this.setEnabled(false);
}
rsu.close();
} else {
if(txt1display.getText().equals("")){
JOptionPane.showMessageDialog(this, "没有公共留言信息");
}else{
//隐藏相册面板
jPanel2.setVisible(false);
//显示公共留言内容
jScrollPane1.setVisible(true);
txt1display.setVisible(true);
//自定义方法
select();
setcbxmId();
jPanel3.setVisible(true);
//隐藏发送留言内容区
jScrollPane2.setVisible(false);
txt1send.setVisible(false);
txt1send.setText("");
//留言-发送键隐藏
btn1send.setVisible(false);
//留言-取消键隐藏
btn1cancle.setVisible(false);
//留言To-对象隐藏
cbxgetname.setVisible(false);
lbl1sendto.setVisible(false);
lbl1send.setVisible(false);
}
}
}
} catch (Exception ex) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -