A. 親有java語言寫的超市管理系統課程設計和源代碼嗎,能給我嗎
package untitled5;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class delbook extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField jTextField3 = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField jTextField4 = new JTextField();
JButton jButton1 = new JButton();
//Construct the frame
public delbook() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(500,400));
this.setTitle("超市管理系統");
jLabel2.setFont(new java.awt.Font("SansSerif", 0, 30));
jLabel2.setText("業務單位信息");
jLabel3.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel3.setText("產品編號");
jTextField1.setText("");
jLabel4.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel4.setText("公司名稱");
jTextField2.setText("");
jLabel5.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel5.setText("訂單號碼");
jTextField3.setText("");
jLabel6.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel6.setText("電 話");
jTextField4.setText("");
jButton1.setFont(new java.awt.Font("SansSerif", 0, 25));
jButton1.setText("提交");
jButton1.addActionListener(new delbook_jButton1_actionAdapter(this));
contentPane.add(jLabel1, new XYConstraints(179, 1, 153, 32));
contentPane.add(jLabel2, new XYConstraints(162, 33, -1, -1));
contentPane.add(jLabel3, new XYConstraints(83, 89, -1, -1));
contentPane.add(jTextField1, new XYConstraints(189, 88, 141, 36));
contentPane.add(jTextField2, new XYConstraints(189, 149, 142, 36));
contentPane.add(jLabel4, new XYConstraints(84, 148, -1, -1));
contentPane.add(jTextField3, new XYConstraints(188, 206, 143, 33));
contentPane.add(jLabel5, new XYConstraints(84, 204, -1, -1));
contentPane.add(jLabel6, new XYConstraints(84, 253, -1, -1));
contentPane.add(jTextField4, new XYConstraints(189, 260, 143, 36));
contentPane.add(jButton1, new XYConstraints(197, 318, -1, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void update() {
try {
//定義顯示的字元串
String str1;
String str2;
String str3;
String str4;
str1 = jTextField1.getText();
str2 = jTextField2.getText();
str3 = jTextField3.getText();
str4 = jTextField4.getText();
//裝載jdbc驅動程序
String driverName = "oracle.jdbc.OracleDriver";
Driver driver = (Driver) Class.forName(driverName).newInstance();
//連接資料庫
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@thsspc0791:1521:liuyong", "hr", "tongfang");
PreparedStatement pstmt = con.prepareStatement(
" insert Customer1('goodID','Name','PID','tel')values(?,?,?,?)");
pstmt.setString(1, str1);
pstmt.setString(2, str2);
pstmt.setString(1, str3);
pstmt.setString(4, str4);
ResultSet res = pstmt.executeQuery();
pstmt.close();
con.close();
}catch (InstantiationException e) {
System.out.println(e.getMessage());
}catch (IllegalAccessException e) {
System.out.println(e.getMessage());
}catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}catch (SQLException edd) {
edd.printStackTrace() ;
System.out.println(edd.getMessage());
}
}
void jButton1_actionPerformed(ActionEvent e) {
update();
}
}
class delbook_jButton1_actionAdapter implements java.awt.event.ActionListener {
delbook adaptee;
delbook_jButton1_actionAdapter(delbook adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
package untitled5;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright © 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class retur extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
//Construct the frame
public retur() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("超市管理系統");
contentPane.add(jLabel1, new XYConstraints(139, 1, 126, 33));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
package untitled5;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.*;
//貨品信息登記
public class Frame2 extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout2 = new XYLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JLabel jLabel5 = new JLabel();
JTextField jTextField3 = new JTextField();
//Construct the frame
public Frame2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(600, 500));
this.setTitle("超市管理系統");
this.addHierarchyBoundsListener(new Frame2_this_hierarchyBoundsAdapter(this));
jLabel1.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel1.setForeground(Color.red);
jLabel1.setText("超市管理系統");
contentPane.setForeground(Color.black);
jLabel2.setFont(new java.awt.Font("SansSerif", 0, 30));
jLabel2.setText("產 品 信 息 展 示");
// statusBar.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel3.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel3.setText("產品名稱");
jTextField1.setText("");
jLabel4.setEnabled(true);
jLabel4.setFont(new java.awt.Font("SansSerif", 0, 20));
jLabel4.setText("產品ID號");
jTextField2.setText("");
jTextField2.addActionListener(new Frame2_jTextField2_actionAdapter(this));
jPanel1.setLayout(xYLayout2);
jLabel5.setFont(new java.awt.Font("SansSerif", 0, 25));
jLabel5.setForeground(Color.red);
jLabel5.setText("該產品詳細信息");
jTextField3.setText("");
contentPane.add(jLabel1, new XYConstraints(237, 0, 153, 40));
contentPane.add(jLabel2, new XYConstraints(200, 47, 231, 58));
contentPane.add(jLabel3, new XYConstraints(47, 102, 101, 42));
contentPane.add(jTextField1, new XYConstraints(128, 108, 112, 34));
contentPane.add(jTextField2, new XYConstraints(361, 107, 109, 36));
contentPane.add(jPanel1, new XYConstraints(75, 166, 453, 277));
jPanel1.add(jScrollPane1, new XYConstraints(14, 8, 433, 221));
jScrollPane1.getViewport().add(jTextField3, null);
jPanel1.add(jLabel5, new XYConstraints(112, 240, -1, -1));
contentPane.add(jLabel4, new XYConstraints(278, 111, -1, -1));
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void Select() {
try {
String str1, str2;
str1 = jTextField1.getText();
str2 = jTextField2.getText();
B. java 的電商系統的完整源碼+文檔
各大網站上都會有一些簡單的實例的,注冊開發去下載看看。
C. 求一個用java寫的學生成績管理信息系統的源代碼,要求有界面,能實現
以下方法實現了用戶界面登陸
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創建一個用戶名標簽
TextField t1=new TextField();//創建一個文本框對象
Label password=new Label("密碼:");//創建一個密碼標簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創建登陸按鈕
Button b2=new Button("取消");//創建取消按鈕
public DengLuJieMian()
{
this.setTitle("學生信息管理系統");//設置窗口標題
this.setLayout(null);//設置窗口布局管理器
username.setBounds(50,40,60,20);//設置姓名標簽的初始位置
this.add(username);// 將姓名標簽組件添加到容器
t1.setBounds(120,40,80,20);// 設置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標簽的初始位置
this.add(password);//將密碼標簽組件添加到容器
t2.setBounds(120,100,80,20);//設置密碼標簽的初始位置
this.add(t2);//將密碼標簽組件添加到容器
b1.setBounds(50,150,60,20);//設置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監聽器
b2.addActionListener(this);// 給取消按鈕添加監聽器
this.setVisible(true);//設置窗口的可見性
this.setSize(300,200);//設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過內部類重寫關閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=null&&pass.equals("000123"))//判斷語句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數
{
new DengLuJieMian();
}
}
以下方法實現了學生界面設計
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創建菜單欄
Menu m1=new Menu("信息");//創建菜單「信息」
MenuItem m11=new MenuItem("插入");//創建「插入」的菜單項
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績");//創建菜單「成績」
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學生界面");//設置窗口標題
this.setLayout(new CardLayout());//設置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將「插入」菜單項添加到「信息」菜單
m1.add(m12); //將「查詢」菜單項添加到「信息」菜單
m2.add(m21); //將「查詢」菜單項添加到「成績」菜單
m11.addActionListener(this); //給「插入」菜單項添加監聽器
m12.addActionListener(this); //給「查詢」菜單項添加監聽器
m21.addActionListener(this); //給「查詢」菜單項添加監聽器
this.setVisible(true); //設置窗口的可見性
this.setSize(300,200); //設置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理「添加信息」事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理「查詢信息」事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理「查詢成績」事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創建一個對象 }
D. java點名系統源代碼
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class test {
static String[] arr;
static boolean flag=true;
static List<String> a;
static JTextField jtf;
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame=new JFrame();
frame.setLayout(new GridLayout(1,2));
JButton button = new JButton("抽獎");
jtf = new JTextField();
frame.add(jtf);
frame.add(button);
a = new ArrayList<String>();
arr = new String[]{"張三","李四","王五"};
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
int i=0;
fond:
while(true){
String str = arr[(int)(Math.random()*arr.length)];
for(String b:a){
if(b.equals(str)){
if(i>=arr.length){
jtf.setText("沒有人了");
break fond;
}
continue fond;
}
i++;
}
a.add(str);
jtf.setText(str);
break;
}
}
});
frame.setSize(500, 500);
frame.setLocation(500, 500);
frame.setVisible(true);
}
}
E. 求java編寫的倉庫管理系統源代碼或詳細設計
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
class 商品 extends Panel
{String 代號,名稱;int 庫存;float 單價;
商品(String 代號,String 名稱,int 庫存,float 單價)
{this.代號=代號;this.名稱=名稱;this.庫存=庫存;this.單價=單價;
}
}
class ShowWin extends JFrame implements ActionListener
{ Hashtable hashtable=null;
JTextField 代號文本框=new JTextField(),
名稱文本框=new JTextField(),
庫存文本框=new JTextField(),
單價文本框=new JTextField(),
查詢文本框=new JTextField(),
查詢信息文本框=new JTextField(),
刪除文本框=new JTextField();
JButton b_add=new JButton("添加商品"),
b_del=new JButton("刪除商品"),
b_xun=new JButton("查詢商品"),
b_xiu=new JButton("修改商品"),
b_show=new JButton("顯示商品清單");
JTextArea 顯示區=new JTextArea(25,10);
ShowWin()
{super("倉庫管理窗口");
hashtable=new Hashtable();
Container con=getContentPane();
JScrollPane pane=new JScrollPane(顯示區);
顯示區.setEditable(false);
JPanel save=new JPanel();
save.setLayout(new GridLayout(8,2));
save.add(new Label("輸入代號:"));
save.add(代號文本框);
save.add(new Label("輸入名稱:"));
save.add(名稱文本框);
save.add(new Label("輸入庫存:"));
save.add(庫存文本框);
save.add(new Label("輸入單價:"));
save.add(單價文本框);
save.add(new Label("單擊添加:"));
save.add(b_add);
save.add(new Label("單擊修改:"));
save.add(b_xiu);
save.add(new Label("輸入查詢代號:"));
save.add(查詢文本框);
save.add(new Label("單擊查詢:"));
save.add(b_xun);
JPanel del=new JPanel();
del.setLayout(new GridLayout(2,2));
del.add(new Label("輸入刪除的代號:"));
del.add(刪除文本框);
del.add(new Label("單擊刪除:"));
del.add(b_del);
JPanel show=new JPanel();
show.setLayout(new BorderLayout());
show.add(pane,BorderLayout.CENTER);
show.add(b_show,BorderLayout.SOUTH);
JSplitPane split_one,split_two;
split_one=new JSplitPane(JSplitPane.VERTICAL_SPLIT,save,del);
split_two=new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,split_one,show);
con.add(split_two,BorderLayout.CENTER);
JPanel xun=new JPanel();
xun.add(new Label("所得信息:"));
xun.add(查詢信息文本框);
xun.setLayout(new GridLayout(2,1));
con.add(xun,BorderLayout.SOUTH);
b_add.addActionListener(this);
b_del.addActionListener(this);
b_xun.addActionListener(this);
b_xiu.addActionListener(this);
b_show.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==b_add)
{String daihao=null,mingcheng=null;int kucun=0;float danjia=0.0f;
daihao=代號文本框.getText();mingcheng=名稱文本框.getText();
kucun=Integer.parseInt(庫存文本框.getText());
danjia=Float.valueOf(單價文本框.getText()).floatValue();
商品 goods=new 商品(daihao,mingcheng,kucun,danjia);
hashtable.put(daihao,goods);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
else if(e.getSource()==b_del)
{String daihao1=刪除文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(daihao1);
{hashtable.remove(daihao1);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_xun)
{ String aa;
aa=查詢文本框.getText();
查詢信息文本框.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 a=(商品)hashtable.get(aa);
查詢信息文本框.setText(" 代號:"+a.代號+" 名稱:"+a.名稱+" 庫存:"+a.庫存+" 單價:"+a.單價);
}
//
else if(e.getSource()==b_xiu)
{ String bb;
bb=代號文本框.getText();
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in=new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); //////
in.close();
}
catch(ClassNotFoundException event){}
catch(IOException event){}
商品 temp=(商品)hashtable.get(bb);
{hashtable.remove(bb);}
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out =new ObjectOutputStream(file);
out.writeObject(hashtable);//
out.close();
}
catch(IOException event){}
String daihao1=null,mingcheng1=null;int kucun1=0;float danjia1=0.0f;
daihao1=代號文本框.getText();mingcheng1=名稱文本框.getText();
kucun1=Integer.parseInt(庫存文本框.getText());
danjia1=Float.valueOf(單價文本框.getText()).floatValue();
商品 goods1=new 商品(daihao1,mingcheng1,kucun1,danjia1);
hashtable.put(daihao1,goods1);
try{FileOutputStream file=new FileOutputStream("goods.txt");
ObjectOutputStream out=new ObjectOutputStream(file);
out.writeObject(hashtable); out.close();
}
catch(IOException event){}
}
//
else if(e.getSource()==b_show)
{ 顯示區.setText(null);
try{FileInputStream come_in=new FileInputStream("goods.txt");
ObjectInputStream in =new ObjectInputStream(come_in);
hashtable=(Hashtable)in.readObject(); ////
}
catch(ClassNotFoundException event){}
catch(IOException event){}
Enumeration enum=hashtable.elements();
while(enum.hasMoreElements())
{ 商品 te=(商品)enum.nextElement();
顯示區.append("商品代號:"+te.代號+" ");
顯示區.append("商品名稱:"+te.名稱+" ");
顯示區.append("商品庫存:"+te.庫存+" ");
顯示區.append("商品單價:"+te.單價+" ");
顯示區.append("\n ");
}
}
}
}
public class LinkListFour
{public static void main(String args[])
{ ShowWin win=new ShowWin();
win.setSize(400,350);
win.setVisible(true);
win.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{ System.exit(0);}});
}
}
F. 急求java學生信息管理系統源代碼,帶有連接資料庫的,萬分感謝
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系統");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成績");
JMenu m4 = new JMenu("獎懲");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系統");
jm21 = new JMenuItem("輸入");
jm22 = new JMenuItem("查詢");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("輸入成績");
jm32 = new JMenuItem("查詢成績");
jm41 = new JMenuItem("獎勵");
jm42 = new JMenuItem("處分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1 = new ImageIcon();
Icon i2 = new ImageIcon();
Icon i3 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("輸入");
jb2 = new JButton(i2);
jb2.setToolTipText("查詢");
jb3 = new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb = new JToolBar("系統工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("學生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jm21 || e.getSource() == jb1){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe, "insert");
this.setTitle("輸入學生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查詢學生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二個:
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("學生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二個:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立資料庫連接遇到異常!");
}
return con;
}
}
第四個:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl = new JLabel("請輸入學號:",SwingConstants.CENTER);
jt = new JTextField();
jb = new JButton("確定");
JPanel jp1 = new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1 = new JLabel("學號:",SwingConstants.CENTER);
j2 = new JLabel("姓名:",SwingConstants.CENTER);
j3 = new JLabel("性別:",SwingConstants.CENTER);
j4 = new JLabel("年齡:",SwingConstants.CENTER);
jt1 = new JTextField(6);
jt1.setEditable(false);
jt2 = new JTextField(6);
jt2.setEditable(false);
jt3 = new JTextField(6);
jt3.setEditable(false);
jt4 = new JTextField(6);
jt4.setEditable(false);
JPanel jp2 = new JPanel(new BorderLayout());
JPanel jp3 = new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
try{
b = s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查詢學生信息遇到異常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a = s.getAge();
Integer i = new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null, "無此學生!");
}
}
}
}
第五個:
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查詢學生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六個:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student {
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo = stuNo;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender = gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入資料庫遇到異常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != null && rs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
資料庫你自己弄吧,我沒時間弄了!初學得多動手哦
G. 求:java實例源代碼
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.*;
public class Counter extends Frame
{
//聲明三個面板的布局
GridLayout gl1,gl2,gl3;
Panel p0,p1,p2,p3;
JTextField tf1;
TextField tf2;
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26;
StringBuffer str;//顯示屏所顯示的字元串
double x,y;//x和y都是運算數
int z;//Z表示單擊了那一個運算符.0表示"+",1表示"-",2表示"*",3表示"/"
static double m;//記憶的數字
public Counter()
{
gl1=new GridLayout(1,4,10,0);//實例化三個面板的布局
gl2=new GridLayout(4,1,0,15);
gl3=new GridLayout(4,5,10,15);
tf1=new JTextField(27);//顯示屏
tf1.setHorizontalAlignment(JTextField.RIGHT);
tf1.setEnabled(false);
tf1.setText("0");
tf2=new TextField(10);//顯示記憶的索引值
tf2.setEditable(false);
//實例化所有按鈕、設置其前景色並注冊監聽器
b0=new Button("Backspace");
b0.setForeground(Color.red);
b0.addActionListener(new Bt());
b1=new Button("CE");
b1.setForeground(Color.red);
b1.addActionListener(new Bt());
b2=new Button("C");
b2.setForeground(Color.red);
b2.addActionListener(new Bt());
b3=new Button("MC");
b3.setForeground(Color.red);
b3.addActionListener(new Bt());
b4=new Button("MR");
b4.setForeground(Color.red);
b4.addActionListener(new Bt());
b5=new Button("MS");
b5.setForeground(Color.red);
b5.addActionListener(new Bt());
b6=new Button("M+");
b6.setForeground(Color.red);
b6.addActionListener(new Bt());
b7=new Button("7");
b7.setForeground(Color.blue);
b7.addActionListener(new Bt());
b8=new Button("8");
b8.setForeground(Color.blue);
b8.addActionListener(new Bt());
b9=new Button("9");
b9.setForeground(Color.blue);
b9.addActionListener(new Bt());
b10=new Button("/");
b10.setForeground(Color.red);
b10.addActionListener(new Bt());
b11=new Button("sqrt");
b11.setForeground(Color.blue);
b11.addActionListener(new Bt());
b12=new Button("4");
b12.setForeground(Color.blue);
b12.addActionListener(new Bt());
b13=new Button("5");
b13.setForeground(Color.blue);
b13.addActionListener(new Bt());
b14=new Button("6");
b14.setForeground(Color.blue);
b14.addActionListener(new Bt());
b15=new Button("*");
b15.setForeground(Color.red);
b15.addActionListener(new Bt());
b16=new Button("%");
b16.setForeground(Color.blue);
b16.addActionListener(new Bt());
b17=new Button("1");
b17.setForeground(Color.blue);
b17.addActionListener(new Bt());
b18=new Button("2");
b18.setForeground(Color.blue);
b18.addActionListener(new Bt());
b19=new Button("3");
b19.setForeground(Color.blue);
b19.addActionListener(new Bt());
b20=new Button("-");
b20.setForeground(Color.red);
b20.addActionListener(new Bt());
b21=new Button("1/X");
b21.setForeground(Color.blue);
b21.addActionListener(new Bt());
b22=new Button("0");
b22.setForeground(Color.blue);
b22.addActionListener(new Bt());
b23=new Button("+/-");
b23.setForeground(Color.blue);
b23.addActionListener(new Bt());
b24=new Button(".");
b24.setForeground(Color.blue);
b24.addActionListener(new Bt());
b25=new Button("+");
b25.setForeground(Color.red);
b25.addActionListener(new Bt());
b26=new Button("=");
b26.setForeground(Color.red);
b26.addActionListener(new Bt());
//實例化四個面板
p0=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
//創建一個空字元串緩沖區
str=new StringBuffer();
//添加面板p0中的組件和設置其在框架中的位置和大小
p0.add(tf1);
p0.setBounds(10,25,300,40);
//添加面板p1中的組件和設置其在框架中的位置和大小
p1.setLayout(gl1);
p1.add(tf2);
p1.add(b0);
p1.add(b1);
p1.add(b2);
p1.setBounds(10,65,300,25);
//添加面板p2中的組件並設置其的框架中的位置和大小
p2.setLayout(gl2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.setBounds(10,110,40,150);
//添加面板p3中的組件並設置其在框架中的位置和大小
p3.setLayout(gl3);//設置p3的布局
p3.add(b7);
p3.add(b8);
p3.add(b9);
p3.add(b10);
p3.add(b11);
p3.add(b12);
p3.add(b13);
p3.add(b14);
p3.add(b15);
p3.add(b16);
p3.add(b17);
p3.add(b18);
p3.add(b19);
p3.add(b20);
p3.add(b21);
p3.add(b22);
p3.add(b23);
p3.add(b24);
p3.add(b25);
p3.add(b26);
p3.setBounds(60,110,250,150);
//設置框架中的布局為空布局並添加4個面板
setLayout(null);
add(p0);
add(p1);
add(p2);
add(p3);
setResizable(false);//禁止調整框架的大小
//匿名類關閉窗口
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e1)
{
System.exit(0);
}
});
setBackground(Color.lightGray);
setBounds(100,100,320,280);
setVisible(true);
}
//構造監聽器
class Bt implements ActionListener
{
public void actionPerformed(ActionEvent e2)
{
try{
if(e2.getSource()==b1)//選擇"CE"清零
{
tf1.setText("0");//把顯示屏清零
str.setLength(0);//清空字元串緩沖區以准備接收新的輸入運算數
}
else if(e2.getSource()==b2)//選擇"C"清零
{
tf1.setText("0");//把顯示屏清零
str.setLength(0);
}
else if(e2.getSource()==b23)//單擊"+/-"選擇輸入的運算數是正數還是負數
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText(""+(-x));
}
else if(e2.getSource()==b25)//單擊加號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);//清空緩沖區以便接收新的另一個運算數
y=0d;
z=0;
}
else if(e2.getSource()==b20)//單擊減號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=1;
}
else if(e2.getSource()==b15)//單擊乘號按鈕獲得x的值和z的值並清空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=2;
}
else if(e2.getSource()==b10)//單擊除號按鈕獲得x的值和z的值並空y的值
{
x=Double.parseDouble(tf1.getText().trim());
str.setLength(0);
y=0d;
z=3;
}
else if(e2.getSource()==b26)//單擊等號按鈕輸出計算結果
{
str.setLength(0);
switch(z)
{
case 0 : tf1.setText(""+(x+y));break;
case 1 : tf1.setText(""+(x-y));break;
case 2 : tf1.setText(""+(x*y));break;
case 3 : tf1.setText(""+(x/y));break;
}
}
else if(e2.getSource()==b24)//單擊"."按鈕輸入小數
{
if(tf1.getText().trim().indexOf(′.′)!=-1)//判斷字元串中是否已經包含了小數點
{
}
else//如果沒數點有小
{
if(tf1.getText().trim().equals("0"))//如果初時顯示為0
{
str.setLength(0);
tf1.setText((str.append("0"+e2.getActionCommand())).toString());
}
else if(tf1.getText().trim().equals(""))//如果初時顯示為空則不做任何操作
{
}
else
{
tf1.setText(str.append(e2.getActionCommand()).toString());
}
}
y=0d;
}
else if(e2.getSource()==b11)//求平方根
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText("數字格式異常");
if(x<0)
tf1.setText("負數沒有平方根");
else
tf1.setText(""+Math.sqrt(x));
str.setLength(0);
y=0d;
}
else if(e2.getSource()==b16)//單擊了"%"按鈕
{
x=Double.parseDouble(tf1.getText().trim());
tf1.setText(""+(0.01*x));
str.setLength(0);
y=0d;
}
else if(e2.getSource()==b21)//單擊了"1/X"按鈕
{
x=Double.parseDouble(tf1.getText().trim());
if(x==0)
{
tf1.setText("除數不能為零");
}
else
{
tf1.setText(""+(1/x));
}
str.setLength(0);
y=0d;
}
else if(e2.getSource()==b3)//MC為清除內存
{
m=0d;
tf2.setText("");
str.setLength(0);
}
else if(e2.getSource()==b4)//MR為重新調用存儲的數據
{
if(tf2.getText().trim()!="")//有記憶數字
{
tf1.setText(""+m);
}
}
else if(e2.getSource()==b5)//MS為存儲顯示的數據
{
m=Double.parseDouble(tf1.getText().trim());
tf2.setText("M");
tf1.setText("0");
str.setLength(0);
}
else if(e2.getSource()==b6)//M+為將顯示的數字與已經存儲的數據相加要查看新的數字單擊MR
{
m=m+Double.parseDouble(tf1.getText().trim());
}
else//選擇的是其他的按鈕
{
if(e2.getSource()==b22)//如果選擇的是"0"這個數字鍵
{
if(tf1.getText().trim().equals("0"))//如果顯示屏顯示的為零不做操作
{
}
else
{
tf1.setText(str.append(e2.getActionCommand()).toString());
y=Double.parseDouble(tf1.getText().trim());
}
}
else if(e2.getSource()==b0)//選擇的是「BackSpace」按鈕
{
if(!tf1.getText().trim().equals("0"))//如果顯示屏顯示的不是零
{
if(str.length()!=1)
{
tf1.setText(str.delete(str.length()-1,str.length()).toString());//可能拋出字元串越界異常
}
else
{
tf1.setText("0");
str.setLength(0);
}
}
y=Double.parseDouble(tf1.getText().trim());
}
else//其他的數字鍵
{
tf1.setText(str.append(e2.getActionCommand()).toString());
y=Double.parseDouble(tf1.getText().trim());
}
}
}
catch(NumberFormatException e){
tf1.setText("數字格式異常");
}
catch( e){
tf1.setText("字元串索引越界");
}
}
}
public static void main(String args[])
{
new Counter();
}
}
H. 用JAVA怎麼編寫停車場管理系統源代碼
importjava.text.SimpleDateFormat;x0dx0aimportjava.util.Date;x0dx0aimportjava.util.Scanner;x0dx0ax0dx0a/*********************************x0dx0a*停車場管理x0dx0a*authorzhangx0dx0a*2013-12-13x0dx0a********************************/{(String[]args){x0dx0aScannersc=newScanner(System.in);x0dx0ax0dx0aSystem.out.println("請入車牌號:");x0dx0aStringcarno=sc.next();x0d=newCarStopManager();x0dx0acarStopManager.setCarNo(carno);//設置車牌號=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");x0dx0aStringsdate=format.format(newDate());x0dx0aSystem.out.println("當前時間(入場時間)是:"+sdate);x0dx0ax0dx0aSystem.out.println("需要開出車場嗎?yes/no:");x0dx0aStringyesno=sc.next();x0dx0ax0dx0aif(yesno.equals("yes")){x0dx0aStringedate=format.format(newDate());x0dx0aSystem.out.println("出場時間是:"+edate);x0dx0a//計算方法x0dx0acarManager(2,sdate,edate,carStopManager);x0dx0a}x0dx0a}x0dx0a/**x0dx0a*計算方法x0dx0a*/(inttype,StringstarTime,x0dx0aStringendTime,CarStopManagercarStopManager){x0dx0ax0dx0aif(type==1){//按月收費x0dx0aSystem.out.println("如若沒有繳納月費請繳納800元,如若繳納將不再提示!");x0dx0a}else{x0dx0a/**x0dx0a*一般不會有停車幾個月的吧?先不考慮停車幾年或者幾個月的x0dx0a*/x0dx0aStringsDay=starTime.substring(8,10);//入場日期(天)x0dx0aStringsHour=starTime.substring(11,13);//入場小時x0dx0aStringsMM=starTime.substring(14,16);//入場分鍾x0dx0ax0dx0aStringeDay=starTime.substring(8,10);//出場日期(天)x0dx0aStringeHour=endTime.substring(11,13);//出廠小時x0dx0aStringeMM=endTime.substring(14,16);//出廠分鍾x0dx0ax0dx0afloatmoney=0;//需繳納的費用x0dx0aintshour=Integer.parseInt(sHour);x0dx0aintehour=Integer.parseInt(eHour);x0dx0aintsmm=Integer.parseInt(sMM);x0dx0aintemm=Integer.parseInt(eMM);x0dx0aintrehour=0;//停車幾個小時x0dx0ax0dx0aif(sDay.equals(eDay)){//同一天x0dx0a//當天6點到20點之間x0dx0aif((shour>=6&&shour<=20)){x0dx0aif(ehour-shour<=6){//6個小時之內x0dx0arehour=(ehour-shour)*60+(emm-smm);//停車多少分鍾x0dx0a//需要繳納的費用前15分鍾免費以後每15分鍾1.5元x0dx0amoney=(rehour/15-15)*1.5f;x0dx0a}else{x0dx0ainthour=ehour-shour-6;//6小時除外剩餘小時數x0dx0arehour=6*60+(emm-smm);//停車多少分鍾x0dx0a//前15分鍾免費以後每15分鍾1.5元超過6小時15分鍾2元x0dx0amoney=((rehour/15-15)*1.5f)+(hour*60/2);x0dx0a}x0dx0a}x0dx0a}else{//跨天20點到6點之間x0dx0a//todox0dx0a}x0dx0aSystem.out.println("您的車牌號是:"+carStopManager.getCarNo()+";\n"+x0dx0a"您此次停車花費的費用是:"+money+"元");x0dx0a}x0dx0a}x0dx0ax0dx0a/**x0dx0a*bean屬性x0dx0a*/x0dx0aprivateStringcarNo;//車牌號;//入場時間;//出場時間x0dx0a/**x0dx0a*無參構造x0dx0a*/x0dx0apublicCarStopManager(){x0dx0asuper();x0dx0a}x0dx0a/**x0dx0a*有參數構造x0dx0a*@paramcarNox0dx0a*@paramstartTimex0dx0a*@paramendTimex0dx0a*/x0dx0apublicCarStopManager(StringcarNo,StringstartTime,StringendTime){x0dx0asuper();x0dx0athis.carNo=carNo;x0dx0athis.startTime=startTime;x0dx0athis.endTime=endTime;x0dx0a}x0dx0a/**x0dx0a*設置get方法x0dx0a*@returnx0dx0a*/x0dx0apublicStringgetCarNo(){x0dx0areturncarNo;x0dx0a}x0dx0a/**x0dx0a*設置set方法x0dx0a*@paramcarNox0dx0a*/x0dx0apublicvoidsetCarNo(StringcarNo){x0dx0athis.carNo=carNo;x0dx0a}(){x0dx0areturnstartTime;x0dx0a}(StringstartTime){x0dx0athis.startTime=startTime;x0dx0a}(){x0dx0areturnendTime;x0dx0a}(StringendTime){x0dx0athis.endTime=endTime;x0dx0a}x0dx0ax0dx0a}