三国武将查询系统//Java访问数据库
程序员文章站
2022-06-15 20:32:47
...
import java.awt.*;import javax.swing.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import javax.swing.ImageIcon;import javax.swing.JTextArea;import javax.swing.JLabel;import java.awt.Color;import java.sql.*;impor
import java.awt.*; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.ImageIcon; import javax.swing.JTextArea; import javax.swing.JLabel; import java.awt.Color; import java.sql.*; import java.applet.Applet; import java.applet.AudioClip; import java.io.File; import java.net.URL; public class start extends JFrame { private String s=new String(); private JTextField input = new JTextField(); private JTextArea myJTextField = new JTextArea(); static Connection connection; static Statement statement ; private JScrollPane scrollBar; private final JLabel lblNewLabel_1 = new JLabel(""); private final JButton btnNewButton_1 = new JButton("\u6309\u667A\u529B\u6392\u5E8F"); private final JButton button = new JButton("\u6309\u6B66\u529B\u6392\u5E8F"); public start() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setBounds(80, 20, 1240, 700); getContentPane().setLayout(null); button.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u6309\u6B66\u529B\u6392\u5E8F.jpg")); button.setFont(new Font("楷体", Font.PLAIN, 18)); button.setBounds(689, 10, 127, 41); getContentPane().add(button); btnNewButton_1.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u6309\u667A\u529B\u6392\u5E8F.jpg")); btnNewButton_1.setFont(new Font("楷体", Font.ITALIC, 18)); btnNewButton_1.setBounds(482, 10, 127, 41); button.addActionListener(new orderlistener()); btnNewButton_1.addActionListener(new orderlistener2()); getContentPane().add(btnNewButton_1); input.setBounds(147, 10, 226, 41); getContentPane().add(input); input.addActionListener(new inputlistener()); myJTextField.setForeground(new Color(255, 0, 0)); myJTextField.setFont(new Font("Monospaced", Font.PLAIN, 13)); myJTextField.setBackground(new Color(255, 255, 102)); myJTextField.setBounds(1, 1, 1000, 600); getContentPane().add(myJTextField); myJTextField.setOpaque(false); JLabel lblNewLabel = new JLabel("\u6B66\u5C06\uFF1A"); lblNewLabel.setFont(new Font("长城行楷体", Font.ITALIC, 28)); lblNewLabel.setBounds(33, 10, 112, 37); getContentPane().add(lblNewLabel); scrollBar = new JScrollPane(myJTextField); scrollBar.setBounds(10, 61, 1000, 600); getContentPane().add(scrollBar); scrollBar.setOpaque(false); scrollBar.getViewport().setOpaque(false); JButton btnNewButton = new JButton("BACK"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u8FD4\u56DE.jpg")); btnNewButton.setFont(new Font("长城行楷体", Font.ITALIC, 22)); btnNewButton.setBounds(898, 13, 94, 30); getContentPane().add(btnNewButton); lblNewLabel_1.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u80CC\u666F.jpg")); lblNewLabel_1.setBounds(0, 0, 1240, 700); getContentPane().add(lblNewLabel_1); btnNewButton.addActionListener(new backlistener()); myJTextField.append("姓"+"\t\t"+"字"+"\t\t"+"武力"+"\t\t"+"智力"+"\t\t"+"德行"+"\t\t"+"兵器"+"\t\t"+"招募地"+"\t\t"+"坐骑\n"); } class inputlistener implements ActionListener { public void actionPerformed(ActionEvent e) { myJTextField.setText("姓"+"\t\t"+"字"+"\t\t"+"武力"+"\t\t"+"智力"+"\t\t"+"德行"+"\t\t"+"兵器"+"\t\t"+"招募地"+"\t\t"+"坐骑\n"); try{ s=input.getText(); String temps=new String(); if(s.equals("all")) { temps="select * from v_hero "; } else { temps="select * from v_hero where 姓名='"+s+"'"; } //System.out.println(temps); ResultSet res=statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\t\t"+res.getString(5)+"\t"+res.getString(6)+"\t"+res.getString(7)+"\t"+res.getString(8)+"\n"); } }catch(SQLException ss ) { myJTextField.append("error!"); } } } class orderlistener implements ActionListener { public void actionPerformed(ActionEvent e) { myJTextField.setText("姓"+"\t\t"+"字"+"\t\t"+"武力"+"\t\t"+"智力"+"\t\t"+"德行"+"\t\t"+"兵器"+"\t\t"+"招募地"+"\t\t"+"坐骑\n"); try{ String temps=new String(); temps="select * from v_hero order by 武力 desc"; ResultSet res=statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\t\t"+res.getString(5)+"\t"+res.getString(6)+"\t"+res.getString(7)+"\t"+res.getString(8)+"\n"); } }catch(SQLException ss ) { myJTextField.append("error!"); } } } class orderlistener2 implements ActionListener { public void actionPerformed(ActionEvent e) { myJTextField.setText("姓"+"\t\t"+"字"+"\t\t"+"武力"+"\t\t"+"智力"+"\t\t"+"德行"+"\t\t"+"兵器"+"\t\t"+"招募地"+"\t\t"+"坐骑\n"); try{ String temps=new String(); temps="select * from v_hero order by 智力 desc"; ResultSet res=statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\t\t"+res.getString(5)+"\t"+res.getString(6)+"\t"+res.getString(7)+"\t"+res.getString(8)+"\n"); } }catch(SQLException ss ) { myJTextField.append("error!"); } } } class backlistener implements ActionListener { public void actionPerformed(ActionEvent e) { start.this.setVisible(false); Login f9=new Login(); f9.setVisible(true); } } public static void main(String[] args) throws SQLException,ClassNotFoundException { //new music(); // System.out.println("ssss"); Class.forName("oracle.jdbc.driver.OracleDriver"); connection =DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:MYSG","scott","scott"); statement =connection.createStatement(); Login log=new Login(); log.setVisible(true); new music().play(new File("F:\\cc.wav")); //start one= new start(); //one.setVisible(true); } }
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.Color; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Toolkit; public class Login extends JFrame { private JPanel contentPane; public Login() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Three Kingdoms of heroes system"); setBounds(80, 20, 1240, 700); contentPane = new JPanel(); contentPane.setBackground(new Color(240, 240, 240)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton btnNewButton = new JButton("New button"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\1308051010460_\u526F\u672C_\u526F\u672Cwww.jpg")); btnNewButton.setBounds(46, 344, 240, 45); contentPane.add(btnNewButton); btnNewButton.addActionListener(new presslistener()); JButton btnNewButton_1 = new JButton("New button"); btnNewButton_1.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\1308051010460_\u526F\u672C_\u526F\u672C_\u526F\u672Cwwwg.jpg")); btnNewButton_1.setBounds(46, 444, 240, 47); contentPane.add(btnNewButton_1); btnNewButton_1.addActionListener(new presslistener2()); JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\13126052172554n4gg4569www.png")); lblNewLabel.setBounds(0, 0,1240, 700); contentPane.add(lblNewLabel); } class presslistener implements ActionListener { public void actionPerformed(ActionEvent e) { Login.this.setVisible(false); select f2=new select(); f2.setVisible(true); } } class presslistener2 implements ActionListener { public void actionPerformed(ActionEvent e) { Login.this.setVisible(false); dba f3=new dba(); f3.setVisible(true); } } }
import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.Toolkit; public class select extends JFrame { private JPanel contentPane; public select() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(0, 0, 1240, 700); setTitle("选择模式"); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton btnNewButton = new JButton("New button"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u82F1\u96C41.jpg")); btnNewButton.setBounds(49, 307, 180, 48); contentPane.add(btnNewButton); btnNewButton.addActionListener(new presslistener()); JButton btnNewButton_1 = new JButton("New button"); btnNewButton_1.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u8BF8\u4FAF1.jpg")); btnNewButton_1.setBounds(49, 407, 180, 48); contentPane.add(btnNewButton_1); btnNewButton_1.addActionListener(new presslistener2()); JButton btnNewButton_2 = new JButton("New button"); btnNewButton_2.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u6218\u4E891.jpg")); btnNewButton_2.setBounds(49, 507, 180, 48); contentPane.add(btnNewButton_2); btnNewButton_2.addActionListener(new presslistener3()); JLabel label = new JLabel(""); label.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\90e150338ea4ea55a65527cef1cddded_\u526F\u672C.jpg")); label.setBounds(0, 0, 1240, 700); contentPane.add(label); } class presslistener implements ActionListener { public void actionPerformed(ActionEvent e) { select.this.setVisible(false); start f4=new start(); f4.setVisible(true); } } class presslistener2 implements ActionListener { public void actionPerformed(ActionEvent e) { select.this.setVisible(false); country f5=new country(); f5.setVisible(true); } } class presslistener3 implements ActionListener { public void actionPerformed(ActionEvent e) { select.this.setVisible(false); war f6=new war(); f6.setVisible(true); } } }
import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JComboBox; import javax.swing.ImageIcon; import java.awt.Toolkit; public class country extends JFrame { private JPanel contentPane; private String s=new String(); private String s2=new String(); private JTextField input = new JTextField(); private JTextField input2 = new JTextField(); private JTextArea myJTextField = new JTextArea(); private JScrollPane scrollBar; private final JLabel label = new JLabel("\u6B66\u5C06\uFF1A"); private final JLabel label_1 = new JLabel("\u4E3B\u516C\uFF1A"); public country() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("武将从属查询"); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); setBounds(80, 20, 1240, 700); getContentPane().setLayout(null); //myJTextField.setOpaque(false); input.setBounds(183, 10, 190, 41); getContentPane().add(input); input.addActionListener(new inputlistener()); input2.setBounds(480, 10, 205, 41); getContentPane().add(input2); input2.addActionListener(new inputlistener()); myJTextField.setForeground(new Color(255, 0, 0)); myJTextField.setFont(new Font("Monospaced", Font.PLAIN, 13)); myJTextField.setBackground(new Color(255, 245, 238)); myJTextField.setBounds(10, 61, 1000, 629); getContentPane().add(myJTextField); input.setBounds(147, 10, 226, 41); scrollBar = new JScrollPane(myJTextField); scrollBar.setBounds(10, 61, 1000, 629); getContentPane().add(scrollBar); label.setFont(new Font("长城行楷体", Font.ITALIC, 28)); label.setBounds(42, 10, 95, 39); myJTextField.setOpaque(false); scrollBar.setOpaque(false); scrollBar.getViewport().setOpaque(false); contentPane.add(label); label_1.setFont(new Font("长城行楷体", Font.ITALIC, 28)); label_1.setBounds(393, 12, 95, 39); contentPane.add(label_1); JButton btnNewButton = new JButton("BACK"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u8FD4\u56DE.jpg")); btnNewButton.setForeground(new Color(255, 0, 0)); btnNewButton.setFont(new Font("长城行楷体", Font.ITALIC, 22)); btnNewButton.setBounds(1061, 21, 95, 30); getContentPane().add(btnNewButton); JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u57CE\u5E02.jpg")); lblNewLabel.setBounds(0, 0, 1240, 700); contentPane.add(lblNewLabel); btnNewButton.addActionListener(new backlistener()); } class inputlistener implements ActionListener { public void actionPerformed(ActionEvent e) { try{ s=input.getText(); s2=input2.getText(); String temps=new String(); if(s2.equals("all")) { myJTextField.setText("主公名"+"\t\t"+"现役武将数"+"\t\t"+"兵力\n"); temps="select hname,num_of_hero,num_of_army from country,hero where country.ono=hero.hno"; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+"\n"); } } else if(s.equals("all")) { myJTextField.setText("武将"+"\t\t "+"主公"+"\t\t "+"忠诚"+"\t\t "+"时期\n"); temps="select * from v_hero_owner"; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\n"); } } else { myJTextField.setText("武将"+"\t\t "+"主公"+"\t\t "+"忠诚"+"\t\t "+"时期\n"); temps="select * from v_hero_owner where 武将='"+s+"' and 主公='"+s2+"'"; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\n"); } } System.out.println(temps); }catch(SQLException ss ) { myJTextField.append("error!"); } } } class backlistener implements ActionListener { public void actionPerformed(ActionEvent e) { country.this.setVisible(false); Login f9=new Login(); f9.setVisible(true); } } }
import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import javax.swing.ImageIcon; import java.awt.Toolkit; public class war extends JFrame { private JPanel contentPane; private String s=new String(); private String s2=new String(); private JTextField input = new JTextField(); private JTextField input2 = new JTextField(); private JTextArea myJTextField = new JTextArea(); private JScrollPane scrollBar; private final JLabel label = new JLabel("\u6B66\u5C06\uFF1A"); private final JLabel label_1 = new JLabel("\u6218\u4E89\uFF1A"); public war() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("战争战绩查询"); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); setBounds(80, 20, 1240, 700); getContentPane().setLayout(null); input.setBounds(183, 10, 190, 41); getContentPane().add(input); input.addActionListener(new inputlistener()); input2.setBounds(491, 10, 231, 41); getContentPane().add(input2); input2.addActionListener(new inputlistener()); myJTextField.setForeground(new Color(255, 0, 0)); myJTextField.setFont(new Font("Monospaced", Font.PLAIN, 13)); myJTextField.setBackground(Color.YELLOW); myJTextField.setBounds(10, 61, 1000, 600); getContentPane().add(myJTextField); input.setBounds(147, 10, 226, 41); scrollBar = new JScrollPane(myJTextField); scrollBar.setBounds(10, 61, 1000, 600); getContentPane().add(scrollBar); label.setFont(new Font("长城行楷体", Font.ITALIC, 27)); label.setBounds(35, 10, 91, 38); contentPane.add(label); label_1.setFont(new Font("长城行楷体", Font.ITALIC, 27)); label_1.setBounds(386, 10, 91, 38); contentPane.add(label_1); myJTextField.setOpaque(false); scrollBar.setOpaque(false); scrollBar.getViewport().setOpaque(false); JButton btnNewButton = new JButton("BACK"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u8FD4\u56DE.jpg")); btnNewButton.setFont(new Font("长城行楷体", Font.ITALIC, 22)); btnNewButton.setBounds(1102, 13, 91, 30); getContentPane().add(btnNewButton); JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u6218\u4E89.jpg")); lblNewLabel.setBounds(0, 0, 1240, 700); contentPane.add(lblNewLabel); btnNewButton.addActionListener(new backlistener()); } class inputlistener implements ActionListener { public void actionPerformed(ActionEvent e) { try{ s=input.getText(); s2=input2.getText(); String temps=new String(); if(s.equals("all")) { myJTextField.setText("武将名"+"\t\t\t"+"参加的战争"+"\t\t\t"+"主要战绩\n"); temps="select * from v_hero_war "; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+"\n"); } } else if(s2.equals("all")) { myJTextField.setText("战争名"+"\t\t "+"参战阵营"+"\t\t "+"战果"+"\t\t "+"战争地点"+"\t\t\t\t"+"时间\n"); temps="select * from war"; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\t\t"+res.getString(4)+"\t\t"+res.getString(5)+"\n"); } } else { myJTextField.setText("武将名"+"\t\t\t"+"参加的战争"+"\t\t\t"+"主要战绩\n"); temps="select * from v_hero_war where 武将='"+s+"' and 战争='"+s2+"'"; ResultSet res=start.statement.executeQuery(temps); while(res.next()) { myJTextField.append(res.getString(1)+"\t\t"+res.getString(2)+"\t\t"+res.getString(3)+"\n"); } } System.out.println(temps); }catch(SQLException ss ) { myJTextField.append("error!"); } } } class backlistener implements ActionListener { public void actionPerformed(ActionEvent e) { war.this.setVisible(false); Login f9=new Login(); f9.setVisible(true); } } }
import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.Font; import java.awt.Color; import java.awt.Toolkit; public class dba extends JFrame { private JPanel contentPane; public dba() { setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\app\\Administrator\\oradata\\mysg\\\u56FE\u6807.png")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(80, 20, 1240, 700); setTitle("欢迎管理"); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton btnNewButton = new JButton("\u589E\u52A0\u6B66\u5C06"); btnNewButton.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u589E\u52A0\u6B66\u5C06.jpg")); btnNewButton.setForeground(new Color(255, 0, 0)); btnNewButton.setBackground(new Color(105, 105, 105)); btnNewButton.setFont(new Font("长城行楷体", Font.ITALIC, 28)); btnNewButton.setBounds(80, 81, 164, 42); contentPane.add(btnNewButton); btnNewButton.addActionListener(new addlistener()); JButton btnNewButton_1 = new JButton("\u5220\u9664\u6B66\u5C06"); btnNewButton_1.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\\u5220\u9664\u6B66\u5C06.jpg")); btnNewButton_1.setForeground(new Color(255, 0, 0)); btnNewButton_1.setFont(new Font("长城行楷体", Font.ITALIC, 28)); btnNewButton_1.setBounds(973, 81, 164, 42); contentPane.add(btnNewButton_1); JLabel lblNewLabel = new JLabel(""); lblNewLabel.setIcon(new ImageIcon("D:\\app\\Administrator\\oradata\\mysg\\Three_Kingdoms.jpg")); lblNewLabel.setBounds(0, 0, 1240, 700); contentPane.add(lblNewLabel); btnNewButton_1.addActionListener(new deletelistener()); } class addlistener implements ActionListener { public void actionPerformed(ActionEvent e) { dba.this.setVisible(false); addhero f7=new addhero(); f7.setVisible(true); } } class deletelistener implements ActionListener { public void actionPerformed(ActionEvent e) { dba.this.setVisible(false); deletehero f8=new deletehero(); f8.setVisible(true); } } }
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JTextField; import javax.swing.JLabel; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; public class addhero extends JFrame { private JPanel contentPane; private JTextField []textField=new JTextField[6]; //private JTextField textField_1; //private JTextField textField_2; //Field textField_3; //private JTextField textField_4; //private JTextField textField_5; JFrame tt; public addhero() { setTitle("增加英雄"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(50, 50, 1000, 701); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); getContentPane().setLayout(null); for(int i=0;iimport java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JTextField; import javax.swing.JLabel; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.ResultSet; import java.sql.SQLException; public class deletehero extends JFrame { private JPanel contentPane; private JTextField textField; JFrame tt; public deletehero() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("删除英雄"); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); textField = new JTextField(); textField.setBounds(125, 55, 195, 63); contentPane.add(textField); textField.setColumns(10); textField.addActionListener(new deletelistener()); JLabel label = new JLabel("\u6B66\u5C06\u540D"); label.setFont(new Font("长城行楷体", Font.ITALIC, 30)); label.setBounds(10, 55, 105, 63); contentPane.add(label); } class deletelistener implements ActionListener { public void actionPerformed(ActionEvent e) { try{ String s=new String(); s=textField.getText(); String temps=new String(); temps="delete from hero where hname='"+s+"'"; System.out.println(temps); ResultSet res=start.statement.executeQuery(temps); tt=new JFrame(); tt.setBounds(100, 100, 500, 80); JButton ta = new JButton("恭喜!武将"+s+"删除成功! 点击返回"); tt.add(ta); tt.setVisible(true); ta.addActionListener(new backlistener()); }catch(SQLException ss ) { textField.setText("error!"); } } } class backlistener implements ActionListener { public void actionPerformed(ActionEvent e) { deletehero.this.setVisible(false); tt.setVisible(false); dba f8=new dba(); f8.setVisible(true); } } }import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; import java.io.File; public class music{ private AudioInputStream stream = null; private AudioFormat format = null; private SourceDataLine m_line; public void play(File fileName) { try { stream = AudioSystem.getAudioInputStream(fileName); // At present, ALAW and ULAW encodings must be converted // to PCM_SIGNED before it can be played format = stream.getFormat(); if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { format = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), 16, format.getChannels(), format.getChannels() * 2, format.getSampleRate(), false); // big endian stream = AudioSystem.getAudioInputStream(format, stream); } // Create the clip DataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat(), AudioSystem.NOT_SPECIFIED); m_line = (SourceDataLine) AudioSystem.getLine(info); m_line.open(stream.getFormat(),m_line.getBufferSize()); m_line.start(); int numRead = 0; byte[] buf = new byte[m_line.getBufferSize()]; while ((numRead = stream.read(buf, 0, buf.length)) >= 0) { int offset = 0; while (offset