admin 管理员组文章数量: 887021
2023年12月17日发(作者:vagrant歌词表达的什么)
.
期中考试:
二、
package Exextra_2;
import .*;
publicclass Test {
publicstaticvoid main
int[] a=newint[10];
Scanner scan=new Scanner<>;
for
a[i]=t<>;
}
int max=a[0];
int min=a[0];
for
ifmax>
max=a[i];
}
for
min=a[i];
}
n<"max="+max+" min="+min>;
}
}
三、
package Exextra_3;
publicclass Point {
privateintx,y;
privatedoubles;
public Point<>{
}
public Point
this.x=x;
this.y=y;
}
publicint getX<>{
returnx;
}
publicvoid setX
this.x=x;
}
publicint getY<>{
returny;
}
1 / 9
.
publicvoid setY
this.y=y;
}
public String toString<>{
return"<"+x+","+y+">";
}
publicdouble distance
int x1=<>;int y1=<>;
int x2=<>;int y2=<>;
s=<
returns;
}
}
package Exextra_3;
publicclass Test {
publicstaticvoid main
Point p1=new Point<4,5>;
Point p2=new Point<2,1>;
double s=ce
n
n
n;
}
}
四、
package Exextra_4;
publicinterface Shape{
publicabstractdouble area<>;
}
package Exextra_4;
publicclass MyCircle implements Shape{
privatedoubler;
public MyCircle
this.r=r;
}
publicdouble area<>{
return *r*r;
}
public String toString<>{
return"circle: r="+r+" area="+<>;
}
}
package Exextra_4;
publicclass MyRectangle implements Shape {
2 / 9
.
privatedoublew,h;
public MyRectangle
this.w=w;
this.h=h;
}
publicdouble area<>{
returnw*h;
}
public String toString<>{
return"Rectangle: width="+w+" "+"height="+h+" area="+<>;
}
}
package Exextra_4;
publicclass Test {
publicstaticvoid main
Shape t1=new MyRectangle<10,5>;
n
Shape t2=new MyCircle<3>;
n
}
}
五、
package Exextra_5;
import .*;
import .*;
import .*;
publicclassMyFrmextends JFrame implements ActionListener{
intm=0;
JButton btn1=new JButton<"点我">;
JButton btn2=new JButton<"清零">;
JLabel lb=new JLabel<"共点击了0次">;
public MyFrm<>{
JPanel jp=
out
ionListener
ionListener
le<"ButtonDemol">;
}
publicvoid actionPerformed
if
m=m+1;
t<"共点击了"+m+"次">;
}
3 / 9
.
if
m=0;
t<"共点击了"+m+"次">;
}
}
publicstaticvoid main
MyFrm frm=new MyFrm<>;
e<400,100>;
ible
}
}
数据库调试:
package mydb;
import .*;
publicclass StudentDao {
private String driver = "bcDriver";
private String url = "jdbc:odbc:mydb";
privatevoid executeUpdate
try {
e
Connection con = nection
Statement cmd = Statement<>;
eUpdate
<>;
} catch
tackTrace<>;
}
}
publicvoid addStudent
String sql = "insert into student values<'" + sno + "','" + sname+
"','" + major + "'," + zg + ">";
executeUpdate
}
publicvoid deleteStudentBySno
String sql = "delete from student where sno='" + sno + "'";
executeUpdate
}
public String[][] queryStudents<> {
String[][] rows = null;
try {
e
Connection con = nection
Statement cmd = Statement<>;
String sql = "select count<*> from student";
4 / 9
.
ResultSet rs = eQuery
<>;
int rowcount = <1>;
rows = new String[rowcount][4];
sql = "select * from student";
rs = eQuery
rowcount = 0;
while <<>> {
for
rows[rowcount][i - 1] = ing;
rowcount++;
}
<>;
} catch
tackTrace<>;
}
return rows;
}
}
package mydb;
import .*;
.*;
import .*;
publicclassMainFrmextends JFrame {
privatevoid initMenu<> {
JMenuBar bar = new JMenuBar<>;
JMenu m1 = new JMenu<"学生管理">;
JMenu m2 = new JMenu<"课程管理">;
JMenuItem m11 = new JMenuItem<"学生信息管理">;
JMenuItem m12 = new JMenuItem<"增加学生">;
JMenuItem m13 = new JMenuItem<"退出">;
ionListener
publicvoid actionPerformed
exit_Clicked<>;
}
}>;
ionListener
publicvoid actionPerformed
newSubFrm_Clicked<>;
}
}>;
ionListener
publicvoid actionPerformed
newAddFrm_Clicked<>;
5 / 9
.
}
}>;
arator<>;
nuBar
}
privatevoid newSubFrm_Clicked<> {
new StudentFrm<>;
}
privatevoid newAddFrm_Clicked<> {
new AddStudent<>;
}
privatevoid exit_Clicked<> {
if
_OPTION>
<0>;
}
public MainFrm<> {
JPanel jp =
initMenu<>;
e<1000, 600>;
ible
aultCloseOperation<_ON_CLOSE>;
}
publicstaticvoid main
new MainFrm<>;
}
}
package mydb;
import .*;
import tTableModel;
import .*;
import .*;
publicclassStudentFrmextends JFrame {
private JTable table = null;
private String[] cols = { "学号", "", "专业", "是否有资格" };
private JButton deleteBtn = new JButton<"删除">;
private StudentDao studentDao = new StudentDao<>;
privatevoid initTable<> {
6 / 9
.
String[][] rows = tudents<>;
for
if <"0".equals
else
rows[i][3] = "有资格";
rows[i][3] = "无资格";
table = new JTable
}
privatevoid updateTable<> {
String[][] rows = tudents<>;
for
if <"0".equals
else
rows[i][3] = "有资格";
rows[i][3] = "无资格";
el
}
privatebooleanisCellEditable
returntrue;
}
privatevoid deleteBtn_Clicked<> {
int row = ectedRow<>;
if
String sno =
StudentBySno
ssageDialog
updateTable<>;
}
}
public StudentFrm<> {
JPanel jp =
initTable<>;
JScrollPane jsp_table = new JScrollPane
发表评论