JAVA 求大神帮忙把下面两端代码注释一下,
期末要答辩,其中两段代码实在是不会(急)Query.javaimportjava.awt.*;importjavax.swing.*;importjava.sql.*;i...
期末要答辩,其中两段代码实在是不会(急)
Query.java
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class Query extends JFrame implements ActionListener
{
JButton button1,button2;
JTextArea ta;
JPanel p=new JPanel();;
Query(String framename)
{
super(framename);
this.setSize(400,500);
this.setLocationRelativeTo(null);
p.setLayout(null); //取消布局管理器
button1=new JButton("全部显示");
button1.setBounds(150,40,100,40);
button1.addActionListener(this);
ta=new JTextArea(5,20);
ta.setBounds(45,100,300,300);
JScrollPane jsp = new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp.setBounds(45,100,300,300);
button2=new JButton("关闭");
button2.setBounds(160,420,60,40);
button2.addActionListener(this);
p.add(button1);
p.add(button2);
p.add(jsp);
this.setContentPane(p);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="关闭"){
this.hide();
new StudentMain("学生基本信息管理系统");
}
else if(e.getActionCommand()=="全部显示")
{
ta.append("学号\t姓名\t性别\t班级");
DataBase.joinDB();
String sqlString="select sno,name,ssex,classNo from stu";
DataBase.query(sqlString);
try{
while(DataBase.rs.next()){
String no=DataBase.rs.getString(1);
String sname=DataBase.rs.getString(2);
String ssex=DataBase.rs.getString(3);
String sclassNo=DataBase.rs.getString(4);
ta.append("\n"+no+"\t"+sname+"\t"+ssex+"\t"+sclassNo);
}
}
catch(Exception m){
}
}
}
} 展开
Query.java
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class Query extends JFrame implements ActionListener
{
JButton button1,button2;
JTextArea ta;
JPanel p=new JPanel();;
Query(String framename)
{
super(framename);
this.setSize(400,500);
this.setLocationRelativeTo(null);
p.setLayout(null); //取消布局管理器
button1=new JButton("全部显示");
button1.setBounds(150,40,100,40);
button1.addActionListener(this);
ta=new JTextArea(5,20);
ta.setBounds(45,100,300,300);
JScrollPane jsp = new JScrollPane(ta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp.setBounds(45,100,300,300);
button2=new JButton("关闭");
button2.setBounds(160,420,60,40);
button2.addActionListener(this);
p.add(button1);
p.add(button2);
p.add(jsp);
this.setContentPane(p);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="关闭"){
this.hide();
new StudentMain("学生基本信息管理系统");
}
else if(e.getActionCommand()=="全部显示")
{
ta.append("学号\t姓名\t性别\t班级");
DataBase.joinDB();
String sqlString="select sno,name,ssex,classNo from stu";
DataBase.query(sqlString);
try{
while(DataBase.rs.next()){
String no=DataBase.rs.getString(1);
String sname=DataBase.rs.getString(2);
String ssex=DataBase.rs.getString(3);
String sclassNo=DataBase.rs.getString(4);
ta.append("\n"+no+"\t"+sname+"\t"+ssex+"\t"+sclassNo);
}
}
catch(Exception m){
}
}
}
} 展开
2个回答
展开全部
上图为代码运行结果。
代码分析如下:
public class Query extends JFrame implements ActionListener {//Query实现接口ActionListener,Query类里的public void actionPerformed(ActionEvent e){}就是从ActionListener接口里继承来的。
JButton button1, button2; //定义图中button1,和button2
JTextArea ta; //定义了图中的jsp
JPanel p = new JPanel();
Query(String framename) {
super(framename);
this.setSize(400, 500);
this.setLocationRelativeTo(null);
p.setLayout(null); // 取消布局管理器
//在这里设置button1的
button1 = new JButton("全部显示");
button1.setBounds(150, 40, 100, 40);
button1.addActionListener(this);
ta = new JTextArea(5, 20);
ta.setBounds(45, 100, 300, 300);
//在这里设置jsp的属性,如长宽和位置
JScrollPane jsp = new JScrollPane(ta,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp.setBounds(45, 100, 300, 300);
//在这里设置button2的按钮的 显示文字、位置、添加侦听事件
button2 = new JButton("关闭");
button2.setBounds(160, 420, 60, 40);
button2.addActionListener(this);
p.add(button1);
p.add(button2);
p.add(jsp);
this.setContentPane(p);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
/*if (e.getActionCommand() == "关闭") {
this.hide();
new StudentMain("学生基本信息管理系统");
} else if (e.getActionCommand() == "全部显示") {
ta.append("学号\t姓名\t性别\t班级");
DataBase.joinDB();
String sqlString = "select sno,name,ssex,classNo from stu";
DataBase.query(sqlString);
try {
while (DataBase.rs.next()) {
String no = DataBase.rs.getString(1);
String sname = DataBase.rs.getString(2);
String ssex = DataBase.rs.getString(3);
String sclassNo = DataBase.rs.getString(4);
ta.append("\n" + no + "\t" + sname + "\t" + ssex + "\t"
+ sclassNo);
}
} catch (Exception m) {
}
}*/
}
public static void main(String[] args){
new Query("test");
}
}
2014-12-28
展开全部
代码好长哦,恐怕没有人会注释的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询