⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookinformation.java

📁 本系统是采用JAVA作为前台开发工具
💻 JAVA
字号:
//信息反馈
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.util.Date;
import java.text.SimpleDateFormat;

public class LookInformation implements ActionListener,ListSelectionListener
{public JLabel lb0,lb1,lb2,lb3,lb4,lb5;
 public JTextField jtfd1,jtfd2,jtfd3,jtfd4;
 public JButton btn1,btn2;
 public JRadioButton jrb1,jrb2;
 public ButtonGroup bg;
 public JTextArea jta;
 public Connection con;
 public Statement stmt;
 public JTable table;
 public String tempString;
 public Object rowData[][];
 public Date nowTime;
 public SimpleDateFormat matter;
 public ListSelectionModel selectionMode=null;
 public  JFrame frame;

public LookInformation()
{JFrame.setDefaultLookAndFeelDecorated(true);
 frame=new JFrame("信息反馈");
 ImageIcon icon=new ImageIcon("images/home.gif");
 frame.setIconImage(icon.getImage());
 frame.setResizable(false);
 Font font1=new Font("宋体",Font.PLAIN,15);
 Container content=frame.getContentPane();
 content.setLayout(null);
 Toolkit tool=frame.getToolkit();
 Dimension wndsize=tool.getScreenSize();
/*************************************创建反馈者信息界面***********************************************************/
 //--初始化各个组件--
 JLabel lb0=new JLabel("姓名:");
 JLabel lb1=new JLabel("性别:");
 JLabel lb2=new JLabel("单位:");
 JLabel lb3=new JLabel("地址:");
 JLabel lb4=new JLabel("E-mail:");
 JLabel lb5=new JLabel("反馈信息:");

 jtfd1=new JTextField();
 jtfd2=new JTextField();
 jtfd3=new JTextField();
 jtfd4=new JTextField();

 jrb1=new JRadioButton("男");
 jrb2=new JRadioButton("女");
 bg=new ButtonGroup();
 bg.add(jrb1);
 bg.add(jrb2);
 jrb1.setSelected(true);
 jta=new JTextArea();
 jta.setLineWrap(true);
 JScrollPane js=new JScrollPane(jta,
             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
             JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

btn1=new JButton("提交",new ImageIcon("images/ImgGetHint.gif"));
btn2=new JButton("撤消",new ImageIcon("images/cancel.gif"));

btn1.addActionListener(this);btn2.addActionListener(this);

 //--设置各个组件的大小和位置--
 lb0.setBounds(130,35,60,25);jtfd1.setBounds(170,35,150,25);
 lb1.setBounds(410,35,60,25);jrb1.setBounds(450,35,40,25);jrb2.setBounds(510,35,40,25);
 lb2.setBounds(630,35,60,25);jtfd2.setBounds(670,35,150,25);
 lb3.setBounds(130,70,60,25);jtfd3.setBounds(170,70,280,25);
 lb4.setBounds(480,70,60,25);jtfd4.setBounds(540,70,280,25);
 lb5.setBounds(130,105,80,25);js.setBounds(210,105,610,80);
 btn1.setBounds(850,60,120,40);btn2.setBounds(850,110,120,40);


 //--设置各个组件的字体--
 lb0.setFont(font1);
 jtfd1.setFont(font1);

 lb1.setFont(font1);
 jtfd2.setFont(font1);

 lb2.setFont(font1);
 jtfd3.setFont(font1);

 lb3.setFont(font1);
 jtfd4.setFont(font1);

 lb4.setFont(font1);
 jrb1.setFont(font1);

 lb5.setFont(font1);
 jrb2.setFont(font1);
 jta.setFont(font1);
 btn1.setFont(font1);
 btn2.setFont(font1);

 //--添加各个组件--
 JPanel pane=new JPanel();
 pane.setLayout(null);
 pane.add(lb0);pane.add(jtfd1);
 pane.add(lb1);pane.add(jrb1);pane.add(jrb2);
 pane.add(lb2);pane.add(jtfd2);
 pane.add(lb3);pane.add(jtfd3);
 pane.add(lb4);pane.add(jtfd4);
 pane.add(lb5);pane.add(js);
 pane.add(btn1);pane.add(btn2);
 pane.setBounds(5,10,wndsize.width-16,200);
 pane.setBorder(
 	 	 		                BorderFactory.createCompoundBorder(
 	 	 		                BorderFactory.createTitledBorder("我的看法"),
	                            BorderFactory.createLoweredBevelBorder()));

/*********************************创建数据表格界面************************************************/
Object columnNames[]={"姓名","性别","单位","地址","电子邮件","反馈信息","反馈日期"};
        rowData=new Object[1000][7];
        table=new JTable(rowData,columnNames);
        table.setRowHeight(20);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        table.setCellSelectionEnabled(true);//使得表格的选取是以cell为单位,而不是以列为单位.若你没有写此行,则在选取表格数
		                                           //据时以整列为单位.
		selectionMode=table.getSelectionModel();//取得table的ListSelectionModel.
   	    selectionMode.addListSelectionListener(this);
        table.setPreferredScrollableViewportSize(new Dimension(500,30));
		JScrollPane scrollPane=new JScrollPane(table,
		                       JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
		                       JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        try{ setnull();}
		catch(SQLException ed){}
		try{ view();}
		catch(SQLException ed){}
		//--设置各个组件的大小和位置--
        scrollPane.setBounds(10,23,wndsize.width-36,wndsize.height-273);

		//--设置各个组件的字体--
		table.setFont(font1);

		//--将各个组件添加到容器中--
		JPanel pane1=new JPanel();
        pane1.setLayout(null);
		pane1.add(scrollPane);
		pane1.setBounds(5,210,wndsize.width-16,wndsize.height-240);
		pane1.setBorder(
		 	 	 		                BorderFactory.createCompoundBorder(
		 	 	 		                BorderFactory.createTitledBorder("反馈信息"),
	                            BorderFactory.createLoweredBevelBorder()));

 content.add(pane);
 content.add(pane1);
 frame.setSize(wndsize);
 frame.setResizable(false);
 frame.setVisible(true);
}
public void valueChanged(ListSelectionEvent el)
{tempString="";
	       //JTable的getSelectedRows()与getSelectedColumns()方法会返回已选取表格cell的index Array数据.
	   	  int[] rows=table.getSelectedRows();
	   	  int[] columns=table.getSelectedColumns();

	       //JTable的getValueAt()方法会返回某行的cell数据,返回值是Object数据类型,因此我们要自行转成String数据类型.
	   	    for (int i=0;i<rows.length;i++){
	   	      for (int j=0;j<columns.length;j++)
	                tempString = tempString+(String)table.getValueAt(rows[i], columns[j]);
	   	    }

	   	   jtfd1.setText(tempString);
	   	   jtfd2.setText(tempString);
	   	   try{ Update();}
		        catch(SQLException ed){}
}
public void Update() throws SQLException
		    { 	String name,sex,danwei,address,email,infor,date;
				String strurl=
								"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
				  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
				  catch (ClassNotFoundException eg) {}
				  con= DriverManager.getConnection(strurl);
				  stmt= con.createStatement();
				  ResultSet rs = stmt.executeQuery("select * from 信息反馈");
				  while(rs.next())
				  {name=rs.getString(1);sex=rs.getString(2);danwei=rs.getString(3);address=rs.getString(4);
				   email=rs.getString(5);infor=rs.getString(6);date=rs.getString(7);
				   if(name.equals(jtfd2.getText().trim()))
				   {jtfd1.setText(name);jtfd2.setText(danwei);jtfd3.setText(address);jtfd4.setText(email);
				    jta.setText(infor);
				    if(sex.equals("男"))
				    {jrb1.setSelected(true);}
				    else if(sex.equals("女"))
				    {jrb2.setSelected(true);}
			        }
				}
	}
/*********************************各个按钮事件代码************************************************/
public void actionPerformed(ActionEvent e)
{ Object obj=(JButton)e.getSource();
  if(obj==btn1)//提交按钮
  {try{ Add();}
   catch(SQLException ed){}
  }
  if(obj==btn2)//撤消按钮
  {jtfd1.setText("");jtfd2.setText("");jtfd3.setText("");jtfd4.setText("");
   jta.setText("");
  }
}
/////////////////////////提交反馈信息代码///////////////////////////////////////////////////////////////
    public void Add() throws SQLException
    {     nowTime=new Date();
   		  matter=new SimpleDateFormat("yyyy-MM-dd");
   		  String man="";
   		  if(jrb1.isSelected())
   		  {man="男";}
   		  else if(jrb2.isSelected())
   		  {man="女";}
		  String strurl=
						"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
		  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
		  catch (ClassNotFoundException eg) {}
		  con= DriverManager.getConnection(strurl);
		  stmt= con.createStatement();
		  ResultSet rs = stmt.executeQuery("select * from 信息反馈 ");
		  while(rs.next())
	      { stmt.executeUpdate("INSERT INTO 信息反馈(姓名,性别,单位,地址,电子邮件,反馈信息,反馈日期) values ('"+jtfd1.getText()+"','"+man+"','"+jtfd2.getText()+"','"+jtfd3.getText()+"','"+jtfd4.getText()+"','"+jta.getText()+"','"+matter+"')");
			JOptionPane.showMessageDialog(null, "感谢您反馈此信息给我们,并愿您天天快乐,事事顺心!");
			try{ setnull();}
		    catch(SQLException ed){}
			try{ view();}
	        catch(SQLException ed){}
		  }
	}
/////////////////////设置信息反馈表格为空///////////////////////////////////////////////////////////////////
public void setnull() throws SQLException
{int i=0;
 try{
     String strurl =
        "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con= DriverManager.getConnection(strurl);
     stmt = con.createStatement();
     ResultSet rs=stmt.executeQuery("SELECT * From 信息反馈");
     while(rs.next())
    {
     rowData[i][0]=null;rowData[i][1]=null;
     rowData[i][2]=null;rowData[i][3]=null;
     rowData[i][4]=null;rowData[i][5]=null;
     rowData[i][6]=null;
 	 i++;
    }
    rowData[i][0]=null;rowData[i][1]=null;
    rowData[i][2]=null;rowData[i][3]=null;
	rowData[i][4]=null;rowData[i][5]=null;
    rowData[i][6]=null;
    table.repaint();
   }

catch(Exception g)
{g.printStackTrace();}

}
    public void view() throws SQLException
    { //--连接表格和数据库--
				int i=0;
				String name,sex,danwei,address,email,infor,date;
				try{
					String strurl1 =
								    "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=DataBase/Library.mdb";
					try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
					catch (ClassNotFoundException eg) {}
					con= DriverManager.getConnection(strurl1);
					stmt= con.createStatement();
					ResultSet rs1 = stmt.executeQuery("select * from 信息反馈 ORDER BY 姓名");
					while(rs1.next())
					{name=rs1.getString(1);sex=rs1.getString(2);danwei=rs1.getString(3);address=rs1.getString(4);
					 email=rs1.getString(5);infor=rs1.getString(6);date=rs1.getString(7);
					 rowData[i][0]=name;rowData[i][1]=sex;rowData[i][2]=danwei;rowData[i][3]=address;
					 rowData[i][4]=email;rowData[i][5]=infor;rowData[i][6]=date;
					 i++;
		             }
		             table.repaint();
	                 con.close();
				    }
				catch(Exception es)
				{es.printStackTrace();}
	}
public static void main(String[]args)
		{   try {
		            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		            }
		        catch(Exception e) {
		            e.printStackTrace();
		           }
			new LookInformation();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -