当前位置: 技术问答>java相关
急!!!100分求两个完整的APPLET源码!晚上来给分!
来源: 互联网 发布时间:2015-07-03
本文导语: 小弟我刚刚开始学 Java,而且还是第一次学编程。 而令我苦恼的是,好多书上的例子都是只有关键部分,好多时候连 main 方法也是省去的! 这样做也许有许多好处,可是对我这种刚刚起步的笨鸟加菜鸟来说,简直就...
小弟我刚刚开始学 Java,而且还是第一次学编程。
而令我苦恼的是,好多书上的例子都是只有关键部分,好多时候连 main 方法也是省去的!
这样做也许有许多好处,可是对我这种刚刚起步的笨鸟加菜鸟来说,简直就是超难受啊!~
所以在这里想求两个自己想了半天但不知道怎么做的简单的 Applet 的完整源码。
希望高手不要笑我,还请多多指教、多多帮助,小弟在此诚恳地说谢谢大家了!
第一个 Applet:
在 SQL Server 的Recruitment 数据库中有三张表:Position、PositionSkill和Skill。内容如下:
Position:
cPositionCode vDescription iBudgetedStrength siYear iCurrentStrength
------------- ----------------------------------- ----------------- ------ ----------------
0001 Sales Manager 100 1997 82
0002 Maketing Manager 100 1997 83
0003 Financial Analyst 50 1997 30
0004 Training Co-ord 20 1997 15
0005 Database Analyst 10 1997 8
0006 Staff Accountant 20 1997 18
0007 Audit Manager 20 1997 18
0008 Telephone Operator 20 1997 18
0009 Office Clerk 20 1997 18
0010 Legal Secretary 20 1997 18
0011 Administrative Assistant 20 1997 18
0012 Senior Receptionist 20 1997 18
0013 Consultant 20 1997 18
0014 Maintenance Technician 20 1997 18
0015 Receptionist 21 1997 18
(15 row(s) affected)
PositionSkill:
cPositionCode cSkillCode
------------- ----------
0001 0001
0001 0006
0002 0001
0002 0006
0003 0001
0004 0001
0004 0002
0004 0003
0004 0005
0004 0006
0005 0001
0005 0005
0005 0006
0006 0001
(14 row(s) affected)
Skill:
cSkillCode vSkill
---------- -----------------------------------
0001 Communication skill
0002 Visual basic
0003 Database Administration
0005 Data Entry
0006 Team leading
0007 Power Builder
0008 Record Keeping
0009 Presentation Skill
0010 Convincing
0011 Learning
0012 Planning
0013 Project Management
0014 Time Keeping
0015 Analytical
0016 MS-Ofice
0017 Initiative
0018 Self Motivation
0019 Scheduling
0020 Interpersonal Skill
0021 Scheduling
(20 row(s) affected)
现在想做一个 Appelt,使得网页打开后,不同的 cPositionCode 不同的表格在 Applet 上更新显示出来。要求显示三张表中的全部相关信息,如果 SQL Server 中没有相关的视图怎么办?能不用视图的么?
而令我苦恼的是,好多书上的例子都是只有关键部分,好多时候连 main 方法也是省去的!
这样做也许有许多好处,可是对我这种刚刚起步的笨鸟加菜鸟来说,简直就是超难受啊!~
所以在这里想求两个自己想了半天但不知道怎么做的简单的 Applet 的完整源码。
希望高手不要笑我,还请多多指教、多多帮助,小弟在此诚恳地说谢谢大家了!
第一个 Applet:
在 SQL Server 的Recruitment 数据库中有三张表:Position、PositionSkill和Skill。内容如下:
Position:
cPositionCode vDescription iBudgetedStrength siYear iCurrentStrength
------------- ----------------------------------- ----------------- ------ ----------------
0001 Sales Manager 100 1997 82
0002 Maketing Manager 100 1997 83
0003 Financial Analyst 50 1997 30
0004 Training Co-ord 20 1997 15
0005 Database Analyst 10 1997 8
0006 Staff Accountant 20 1997 18
0007 Audit Manager 20 1997 18
0008 Telephone Operator 20 1997 18
0009 Office Clerk 20 1997 18
0010 Legal Secretary 20 1997 18
0011 Administrative Assistant 20 1997 18
0012 Senior Receptionist 20 1997 18
0013 Consultant 20 1997 18
0014 Maintenance Technician 20 1997 18
0015 Receptionist 21 1997 18
(15 row(s) affected)
PositionSkill:
cPositionCode cSkillCode
------------- ----------
0001 0001
0001 0006
0002 0001
0002 0006
0003 0001
0004 0001
0004 0002
0004 0003
0004 0005
0004 0006
0005 0001
0005 0005
0005 0006
0006 0001
(14 row(s) affected)
Skill:
cSkillCode vSkill
---------- -----------------------------------
0001 Communication skill
0002 Visual basic
0003 Database Administration
0005 Data Entry
0006 Team leading
0007 Power Builder
0008 Record Keeping
0009 Presentation Skill
0010 Convincing
0011 Learning
0012 Planning
0013 Project Management
0014 Time Keeping
0015 Analytical
0016 MS-Ofice
0017 Initiative
0018 Self Motivation
0019 Scheduling
0020 Interpersonal Skill
0021 Scheduling
(20 row(s) affected)
现在想做一个 Appelt,使得网页打开后,不同的 cPositionCode 不同的表格在 Applet 上更新显示出来。要求显示三张表中的全部相关信息,如果 SQL Server 中没有相关的视图怎么办?能不用视图的么?
|
得了,贴出来算了。注意将例中的数据获取结果集部分换成你自己的
另外private static boolean SCROLLABLE = false;是用来表示你的数据库是否支持滚动光标,如果是,就定义为true。
/**
* @version 1.00 1999-07-17
* @author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class ResultSetTable
{ public static void main(String[] args)
{ JFrame frame = new ResultSetFrame();
frame.show();
}
}
/* this class is the base class for the scrolling and the
caching result set table model. It stores the result set
and its metadata.
*/
abstract class ResultSetTableModel extends AbstractTableModel
{ public ResultSetTableModel(ResultSet aResultSet)
{ rs = aResultSet;
try
{ rsmd = rs.getMetaData();
}
catch(SQLException e)
{ System.out.println("Error " + e);
}
}
public String getColumnName(int c)
{ try
{ return rsmd.getColumnName(c + 1);
}
catch(SQLException e)
{ System.out.println("Error " + e);
return "";
}
}
public int getColumnCount()
{ try
{ return rsmd.getColumnCount();
}
catch(SQLException e)
{ System.out.println("Error " + e);
return 0;
}
}
protected ResultSet getResultSet()
{ return rs;
}
private ResultSet rs;
private ResultSetMetaData rsmd;
}
/* this class uses a scrolling cursor, a JDBC 2 feature
*/
class ScrollingResultSetTableModel extends ResultSetTableModel
{ public ScrollingResultSetTableModel(ResultSet aResultSet)
{ super(aResultSet);
}
public Object getValueAt(int r, int c)
{ try
{ ResultSet rs = getResultSet();
rs.absolute(r + 1);
return rs.getObject(c + 1);
}
catch(SQLException e)
{ System.out.println("Error " + e);
return null;
}
}
public int getRowCount()
{ try
{ ResultSet rs = getResultSet();
rs.last();
return rs.getRow();
}
catch(SQLException e)
{ System.out.println("Error " + e);
return 0;
}
}
}
/* this class caches the result set data; it can be used
if scrolling cursors are not supported
*/
class CachingResultSetTableModel extends ResultSetTableModel
{ public CachingResultSetTableModel(ResultSet aResultSet)
{ super(aResultSet);
try
{ cache = new ArrayList();
int cols = getColumnCount();
ResultSet rs = getResultSet();
/* place all data in an array list of Object[] arrays
We don't use an Object[][] because we don't know
how many rows are in the result set
*/
while (rs.next())
{ Object[] row = new Object[cols];
for (int j = 0; j
另外private static boolean SCROLLABLE = false;是用来表示你的数据库是否支持滚动光标,如果是,就定义为true。
/**
* @version 1.00 1999-07-17
* @author Cay Horstmann
*/
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class ResultSetTable
{ public static void main(String[] args)
{ JFrame frame = new ResultSetFrame();
frame.show();
}
}
/* this class is the base class for the scrolling and the
caching result set table model. It stores the result set
and its metadata.
*/
abstract class ResultSetTableModel extends AbstractTableModel
{ public ResultSetTableModel(ResultSet aResultSet)
{ rs = aResultSet;
try
{ rsmd = rs.getMetaData();
}
catch(SQLException e)
{ System.out.println("Error " + e);
}
}
public String getColumnName(int c)
{ try
{ return rsmd.getColumnName(c + 1);
}
catch(SQLException e)
{ System.out.println("Error " + e);
return "";
}
}
public int getColumnCount()
{ try
{ return rsmd.getColumnCount();
}
catch(SQLException e)
{ System.out.println("Error " + e);
return 0;
}
}
protected ResultSet getResultSet()
{ return rs;
}
private ResultSet rs;
private ResultSetMetaData rsmd;
}
/* this class uses a scrolling cursor, a JDBC 2 feature
*/
class ScrollingResultSetTableModel extends ResultSetTableModel
{ public ScrollingResultSetTableModel(ResultSet aResultSet)
{ super(aResultSet);
}
public Object getValueAt(int r, int c)
{ try
{ ResultSet rs = getResultSet();
rs.absolute(r + 1);
return rs.getObject(c + 1);
}
catch(SQLException e)
{ System.out.println("Error " + e);
return null;
}
}
public int getRowCount()
{ try
{ ResultSet rs = getResultSet();
rs.last();
return rs.getRow();
}
catch(SQLException e)
{ System.out.println("Error " + e);
return 0;
}
}
}
/* this class caches the result set data; it can be used
if scrolling cursors are not supported
*/
class CachingResultSetTableModel extends ResultSetTableModel
{ public CachingResultSetTableModel(ResultSet aResultSet)
{ super(aResultSet);
try
{ cache = new ArrayList();
int cols = getColumnCount();
ResultSet rs = getResultSet();
/* place all data in an array list of Object[] arrays
We don't use an Object[][] because we don't know
how many rows are in the result set
*/
while (rs.next())
{ Object[] row = new Object[cols];
for (int j = 0; j