📄 yue.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class yue extends JFrame implements ActionListener{
private JMenuItem 浏览用户,添加用户,订购,报纸查询,退出,订购查询,客户统计,总金额,用户金额;
JRadioButton b1,b2;
ButtonGroup g;
static final String JDBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
static final String DATABASE_URL = "jdbc:odbc:PostofficeDSN";
private Connection connection;
private Statement statement;
String sqlString ;
public yue(){
super("hao");
浏览用户=new JMenuItem("浏览用户");
添加用户=new JMenuItem("添加用户");
退出=new JMenuItem("退出");
订购=new JMenuItem("订购");
JMenu 系统=new JMenu("系统");
系统.add(浏览用户);系统.add(添加用户);系统.add(退出);系统.add(订购);
JMenu 查询=new JMenu("查询");
报纸查询=new JMenuItem("报纸查询");订购查询=new JMenuItem("订购查询");
查询.add(报纸查询);查询.add(订购查询);
JMenu 统计=new JMenu("统计");
客户统计=new JMenuItem("客户统计");总金额=new JMenuItem("总金额");用户金额=new JMenuItem("用户金额");
统计.add(客户统计);统计.add(总金额);统计.add(用户金额);
JMenuBar bar=new JMenuBar();
setJMenuBar(bar);
bar.add(系统);bar.add(查询);bar.add(统计);
报纸查询.addActionListener(this);
订购查询.addActionListener(this);客户统计.addActionListener(this);
总金额.addActionListener(this);用户金额.addActionListener(this);
浏览用户.addActionListener(this);
添加用户.addActionListener(this);订购.addActionListener(this);
退出.addActionListener(this);
Container c=getContentPane();
c.setLayout(new GridLayout(2,2));
setSize(600,600);setVisible(true);
initialize();
}
public void initialize()
{
try {
String login="sa";//JOptionPane.showInputDialog("usename:");
String password="123";//JOptionPane.showInputDialog("password:");
Class.forName( JDBC_DRIVER );
connection = DriverManager.getConnection( DATABASE_URL,login,password );
statement = connection.createStatement();
}
catch ( SQLException sqlException ) {
JOptionPane.showMessageDialog( null, sqlException.getMessage(),
"Database Error", JOptionPane.ERROR_MESSAGE );
System.exit( 1 );
}
catch ( ClassNotFoundException classNotFound ) {
JOptionPane.showMessageDialog( null, classNotFound.getMessage(),
"Driver Not Found", JOptionPane.ERROR_MESSAGE );
System.exit( 1 );
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==退出){
try {
statement.close();
connection.close();
}
catch ( SQLException sqlException ) {
sqlException.printStackTrace();
}
System.exit(0);}
if(e.getSource()==添加用户) new AddcustomerFrame(0);
if(e.getSource()==浏览用户) new DisplayQueryResults(0);
if(e.getSource()==报纸查询) new DisplayQueryResults(1);
if(e.getSource()==订购查询) new DisplayQueryResults(2);
if(e.getSource()==客户统计) new DisplayQueryResults(3);
if(e.getSource()==总金额) new DisplayQueryResults(4);
if(e.getSource()==用户金额) new DisplayQueryResults(5);
if(e.getSource()==订购) new adddinggou();
}
public static void main(String args[]){new yue();}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -