?? jmenudemo.java
字號(hào):
//文件名:JMenuDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class JMenuDemo extends JMenuBar {
JDesktopPane desktop = new JDesktopPane();
// JDBCSample jdb=new JDBCSample();
//定義菜單名稱
String[ ] fileItems = new String[ ] { "學(xué)生自然信息", "學(xué)生分?jǐn)?shù)","刪除列表", "退出" };
String[ ] editItems = new String[ ] { "運(yùn)行計(jì)算獎(jiǎng)學(xué)金","一等獎(jiǎng)學(xué)金","二等獎(jiǎng)學(xué)金","三等獎(jiǎng)學(xué)金" };
String[ ] editItems1 = new String[ ] { "平均分?jǐn)?shù)" };
//定義快捷鍵字母
char[ ] fileShortcuts = { 'N','O','S','X' };
char[ ] editShortcuts = { 'Z','X','C','V' };
public JMenuDemo( ) {
//構(gòu)造菜單
JMenu fileMenu = new JMenu("學(xué)生基本信息");
JMenu editMenu = new JMenu("獎(jiǎng)學(xué)金評(píng)定");
JMenu editMenu1 = new JMenu("學(xué)生平均成績(jī)顯示");
//監(jiān)聽菜單的選擇
ActionListener printListener = new ActionListener( ) {
public void actionPerformed(ActionEvent event) {
String ac = event.getActionCommand();
getRootPane().getContentPane().add(desktop, BorderLayout.CENTER);
System.out.println("菜單 對(duì)象 [" + ac + "] 被點(diǎn)擊.");
if (ac=="退出")
{
if (ac=="退出")
System.exit(1);
}
if (ac=="學(xué)生自然信息")
{
// JDBCSample jdb=new JDBCSample();
Jdbcsql jsql=new Jdbcsql();
Desktop dsk=new Desktop();
try
{
Class.forName(jsql.drv);
}
catch(ClassNotFoundException e)
{
System.out.println("Unable to load Driver Class");
return;
}
try
{
Connection con = DriverManager.getConnection(jsql.con,"root","luanluan");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select sid,sname,grade,dept,sclass,gental from student");
Object[][] data=new Object [25][9];
int i=0;
while(rs.next())
{
data[i][0]=rs.getString("sid");
data[i][1]=rs.getString("sname");
data[i][2]=rs.getString("grade");
data[i][3]=rs.getString("dept");
data[i][4]=rs.getString("sclass");
data[i][5]=rs.getString("gental");
i++;
}
JInternalFrame iframe=new JInternalFrame(ac,true,true,true,true);
String[] columnNames = jsql.col;
final JTable jtb = new JTable(data, columnNames);
jtb.setPreferredScrollableViewportSize(new Dimension(500,370));
iframe.getContentPane().add(jtb);
JScrollPane scroPanel = new JScrollPane();
scroPanel.getViewport().setBackground(Color.white);
scroPanel.getViewport().add(jtb);
iframe.getContentPane().add(scroPanel, BorderLayout.NORTH);
desktop.add(iframe);
iframe.setVisible(true);
iframe.setSize(500,400);
rs.close();
stmt.close();
con.close();
}
catch(SQLException se)
{
System.out.println("SQL exception: "+se.getMessage());
se.printStackTrace(System.out);
}
}
if (ac=="學(xué)生分?jǐn)?shù)")
{
Jdbcsql jsql=new Jdbcsql();
Desktop dsk=new Desktop();
try
{
Class.forName(jsql.drv);
}
catch(ClassNotFoundException e)
{
System.out.println("Unable to load Driver Class");
return;
}
try
{
Connection con = DriverManager.getConnection(jsql.con,"root","luanluan");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(jsql.sql2);
Object[][] data=new Object [1000][6];
int i=0;
while(rs.next())
{
data[i][0]=rs.getString("sid1");
data[i][1]=rs.getString("cid1");
data[i][2]=rs.getString("scgrade");
i++;
}
JInternalFrame iframe=new JInternalFrame(ac,true,true,true,true);
String[] columnNames = jsql.col1;
final JTable jtb = new JTable(data, columnNames);
jtb.setPreferredScrollableViewportSize(new Dimension(500,370));
iframe.getContentPane().add(jtb);
JScrollPane scroPanel = new JScrollPane();
scroPanel.getViewport().setBackground(Color.white);
scroPanel.getViewport().add(jtb);
iframe.getContentPane().add(scroPanel, BorderLayout.NORTH);
desktop.add(iframe);
iframe.setVisible(true);
iframe.setSize(480,400);
rs.close();
stmt.close();
con.close();
}
catch(SQLException se)
{
System.out.println("SQL exception: "+se.getMessage());
se.printStackTrace(System.out);
}
}
if (ac=="一等獎(jiǎng)學(xué)金")
{
Jdbcsql jsql=new Jdbcsql();
Desktop dsk=new Desktop();
try
{
Class.forName(jsql.drv);
}
catch(ClassNotFoundException e)
{
System.out.println("Unable to load Driver Class");
return;
}
try
{
Connection con = DriverManager.getConnection(jsql.con,"root","luanluan");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(jsql.sql8);
Object[][] data=new Object [10][6];
int i=0;
while(rs.next())
{
data[i][0]=rs.getString("num");
data[i][1]=rs.getString("sid");
data[i][2]=rs.getString("sname");
data[i][3]=rs.getString("av");
i++;
}
JInternalFrame iframe=new JInternalFrame(ac,true,true,true,true);
String[] columnNames = jsql.col2;
final JTable jtb = new JTable(data, columnNames);
jtb.setPreferredScrollableViewportSize(new Dimension(500,370));
iframe.getContentPane().add(jtb);
JScrollPane scroPanel = new JScrollPane();
scroPanel.getViewport().setBackground(Color.white);
scroPanel.getViewport().add(jtb);
iframe.getContentPane().add(scroPanel, BorderLayout.NORTH);
desktop.add(iframe);
iframe.setVisible(true);
iframe.setSize(480,400);
rs.close();
stmt.close();
con.close();
}
catch(SQLException se)
{
System.out.println("SQL exception: "+se.getMessage());
se.printStackTrace(System.out);
}
}
if (ac=="二等獎(jiǎng)學(xué)金")
{
Jdbcsql jsql=new Jdbcsql();
Desktop dsk=new Desktop();
try
{
Class.forName(jsql.drv);
}
catch(ClassNotFoundException e)
{
System.out.println("Unable to load Driver Class");
return;
}
try
{
Connection con = DriverManager.getConnection(jsql.con,"root","luanluan");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(jsql.sql9);
Object[][] data=new Object [10][6];
int i=0;
while(rs.next())
{
data[i][0]=rs.getString("num");
data[i][1]=rs.getString("sid");
data[i][2]=rs.getString("sname");
data[i][3]=rs.getString("av");
i++;
}
JInternalFrame iframe=new JInternalFrame(ac,true,true,true,true);
String[] columnNames = jsql.col2;
final JTable jtb = new JTable(data, columnNames);
jtb.setPreferredScrollableViewportSize(new Dimension(500,370));
iframe.getContentPane().add(jtb);
JScrollPane scroPanel = new JScrollPane();
scroPanel.getViewport().setBackground(Color.white);
scroPanel.getViewport().add(jtb);
iframe.getContentPane().add(scroPanel, BorderLayout.NORTH);
desktop.add(iframe);
iframe.setVisible(true);
iframe.setSize(480,400);
rs.close();
stmt.close();
con.close();
}
catch(SQLException se)
{
System.out.println("SQL exception: "+se.getMessage());
se.printStackTrace(System.out);
}
}
if (ac=="三等獎(jiǎng)學(xué)金")
{
Jdbcsql jsql=new Jdbcsql();
Desktop dsk=new Desktop();
try
{
Class.forName(jsql.drv);
}
catch(ClassNotFoundException e)
{
System.out.println("Unable to load Driver Class");
return;
}
try
{
Connection con = DriverManager.getConnection(jsql.con,"root","luanluan");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(jsql.sql10);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -