public class Matriculate {
我們擁有十余年網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站建設(shè)經(jīng)驗(yàn),從網(wǎng)站策劃到網(wǎng)站制作,我們的網(wǎng)頁(yè)設(shè)計(jì)師為您提供的解決方案。為企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、微信開(kāi)發(fā)、小程序制作、手機(jī)網(wǎng)站制作、H5開(kāi)發(fā)、等業(yè)務(wù)。無(wú)論您有什么樣的網(wǎng)站設(shè)計(jì)或者設(shè)計(jì)方案要求,我們都將富于創(chuàng)造性的提供專(zhuān)業(yè)設(shè)計(jì)服務(wù)并滿足您的需求。
private int score=400;
public int isMatriculate(Student stu){
if (stu.getIntgretResult()=score||(stu.getIntgretResult()=300stu.getSports()=90)) {
return 1;
}else {
return 0;
}
}
public static void main(String[] args) throws Exception {
Student stu1=new Student("zhangsan",1);
stu1.setIntgretResult(400);
Student stu2=new Student("lisi",2);
stu2.setSports(85);
stu2.setIntgretResult(356);
Matriculate m=new Matriculate();
int c1=m.isMatriculate(stu1);
if (c10) {
System.out.println("id:"+stu1.getId()+"\tname:"+stu1.getName()
+"\tIntgretResult:"+stu1.getIntgretResult()+"\tsports"+stu1.getSports());
System.out.println("被錄取");
}
int c2=m.isMatriculate(stu2);
if (c20) {
System.out.println("id:"+stu2.getId()+"\tname:"+stu2.getName()
+"\tIntgretResult:"+stu2.getIntgretResult()+"\tsports"+stu2.getSports());
System.out.println("被錄取");
}
}
}
class School{
public School(){}
public School(String schoolname, double scoreLine) {
this.schoolname = schoolname;
this.scoreLine = scoreLine;
}
private String schoolname;
private double scoreLine;
public String getSchoolname() {
return schoolname;
}
public double getScoreLine() {
return scoreLine;
}
}
class Student{
public Student(){}
public Student(String name, int id) {
this.name = name;
this.id = id;
}
private String name;
private int id;
private double intgretResult;
private int sports;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getIntgretResult() {
return intgretResult;
}
public void setIntgretResult(double intgretResult) {
this.intgretResult = intgretResult;
}
public int getSports() {
return sports;
}
public void setSports(int sports) {
this.sports = sports;
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class TestString {
public static void main(String[] args) throws IOException {
boolean flag = false;
do {
System.out.println();
System.out.println("Do you want to continue?(Y/N)");
Scanner scan = new Scanner(System.in);
String banlance = scan.next();
if (banlance.equals("Y")) {
flag = true;
} else if(banlance.equals("N")) {
System.out.println("End!");
break;
} else {
System.out.println("Error Input!");
}
System.out.print("Please input the String: ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String str = br.readLine();
StringBuffer strBuffer = new StringBuffer(str);
for(int i=0; istrBuffer.length(); i++) {//將元音字母先刪掉
char c = strBuffer.charAt(i);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
}
}
for(int i=0,j=i+1; jstrBuffer.length(); i++,j++) {//處理重復(fù)輔音字母
char c1 = strBuffer.charAt(i), c2 = strBuffer.charAt(j);
if(c1 == c2) {
strBuffer = strBuffer.deleteCharAt(i);
--i;
--j;
}
}
System.out.println(strBuffer);
} while (flag = true);
}
}
測(cè)試與結(jié)果:
你這個(gè)程序不算大。
但有很多地方的信息很不明確。比如說(shuō):你的數(shù)據(jù)庫(kù)系統(tǒng)是什么?表結(jié)構(gòu)?
如果說(shuō)你想就靠分白拿這么多功能的JAVA代碼應(yīng)該也是不可能的。
建議你一個(gè)模塊一個(gè)模塊的問(wèn)。在別人的幫助下你再想辦法自己整合一下。
這樣的題一般大學(xué)做畢業(yè)設(shè)計(jì)應(yīng)該可以了。做出來(lái)都可以賣(mài)錢(qián)的!!
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class p1 extends Panel
{
Label l1;
Font f=new Font("宋體",Font.BOLD,20);
p1()
{
setLayout(new GridLayout(1,1));
l1=new Label("網(wǎng)上選課記錄系統(tǒng)",Label.CENTER);
l1.setFont(f);
add(l1);
}
}
class p2 extends Panel
{
Label l1,l2;
TextField t1,t2;
p2()
{
setLayout(new GridLayout(1,4));
l1=new Label("姓名",Label.CENTER);
l2=new Label("學(xué)號(hào)",Label.CENTER);
t1=new TextField(10);
t2=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
}
}
class p3 extends Panel
{
Label l1,l2;
TextField t1,t2;
p3()
{
setLayout(new GridLayout(1,4));
l1=new Label("專(zhuān)業(yè)",Label.CENTER);
l2=new Label("所屬院(系)",Label.CENTER);
t1=new TextField(10);
t2=new TextField(10);
add(l1);
add(t1);
add(l2);
add(t2);
}
}
class p4 extends Panel
{
Label l1;
Button btn1;
Button btn2;
Button btn3;
Font f=new Font("宋體",Font.BOLD,20);
p4()
{
setLayout(new GridLayout(1,4));
l1=new Label("請(qǐng)選擇您要選修的課程并確認(rèn)",Label.CENTER);
btn1=new Button("查詢");
btn2=new Button("確認(rèn)");
btn3=new Button("退出系統(tǒng)");
add(l1);
add(btn1);
add(btn2);
add(btn3);
}
}
class p5 extends Panel
{
List list ;
p5()
{
setLayout(new GridLayout(1,1));
list=new List(8,true);
list.add("大學(xué)英語(yǔ)");
list.add("計(jì)算機(jī)圖形學(xué)");
list.add("JAVA語(yǔ)言");
list.add("高等數(shù)學(xué)");
list.add("數(shù)據(jù)結(jié)構(gòu)");
list.add("單片機(jī)");
list.add("網(wǎng)絡(luò)應(yīng)用與開(kāi)發(fā)");
list.add("概率論與數(shù)理統(tǒng)計(jì)");
list.add("管理學(xué)概論");
list.add("數(shù)據(jù)庫(kù)概論");
list.add("英語(yǔ)聽(tīng)力");
list.add("VC++");
list.add("商務(wù)英語(yǔ)");
list.add("會(huì)計(jì)學(xué)");
list.add("經(jīng)濟(jì)學(xué)");
list.add("計(jì)算機(jī)網(wǎng)絡(luò)");
add(list);
}
}
class p6 extends Panel
{
TextArea ta;
p6()
{
setLayout(new GridLayout(1,1));
ta=new TextArea(8,30);
add(ta);
}
}
class p8 extends Panel
{
Label l1,l2,l3;
Label l4,l5,l6,l7,l9;
Panel p11,p22,p33,p44,p55;
TextField t1,t2;
Button btn;
p8()
{
p11=new Panel();
p22=new Panel();
p33=new Panel();
p44=new Panel();
p55=new Panel();
p11.setLayout(new GridLayout(1,1));
p22.setLayout(new GridLayout(1,1));
p33.setLayout(new GridLayout(1,4));
p44.setLayout(new GridLayout(1,4));
p55.setLayout(new GridLayout(1,1));
l4=new Label("");
l5=new Label("");
l6=new Label("");
l7=new Label("");
l9=new Label("");
l1=new Label("歡迎來(lái)到網(wǎng)上選課系統(tǒng)",Label.CENTER);
Font f=new Font("宋體",Font.BOLD,30);
l1.setFont(f);
l2=new Label("請(qǐng)輸入管理員帳號(hào)",Label.CENTER);
l3=new Label("請(qǐng)輸入管理員密碼",Label.CENTER);
setBackground(Color.lightGray);
btn=new Button("確定");
t1=new TextField(20);
t2=new TextField(15);
t2.setEchoChar(′*′);
l1.setForeground(Color.magenta);
t1.setBackground(Color.cyan);
t2.setBackground(Color.cyan);
t1.setForeground(Color.red);
t2.setForeground(Color.red);
l2.setForeground(Color.blue);
l3.setForeground(Color.blue);
p11.add(l1);
p22.add(l4);
p33.add(l5);
p33.add(l2);
p33.add(t1);
p33.add(l6);
p44.add(l7);
p44.add(l3);
p44.add(t2);
p44.add(btn);
p55.add(l9);
setLayout(new GridLayout(5,1));
add(p11);
add(p22);
add(p33);
add(p44);
add(p55);
}
}
class p9 extends Panel
{
p1 pn1=new p1();
p2 pn2=new p2();
p3 pn3=new p3();
p4 pn4=new p4();
p5 pn5=new p5();
p6 pn6=new p6();
p9()
{
setLayout(new GridLayout(6,1));
add(pn1);
add(pn2);
add(pn3);
add(pn4);
add(pn5);
add(pn6);
}
}
class user
{
String username;
String sd;
String major;
String institute;
String course;
user(String x1,String x2,String x3,String x4,String x5)
{
username=x1;
sd=x2;
major=x3;
institute=x4;
course=x5;
}
}
public class www
{
public static void main(String args[])
{
new m();
}
}
class m extends Frame implements ActionListener,ItemListener
{
StringBuffer ss=new StringBuffer("您好!您選修的課程有:");
Vector xiang=new Vector();
p9 pn9;
p8 pn8;
CardLayout cc=new CardLayout();
Button btn1;
Dialog d1;
m()
{
super("網(wǎng)上選課");
pn8=new p8();
pn9=new p9();
setLayout(cc);
add("one",pn8);
add("two",pn9);
btn1=new Button("確定");
pn9.pn1.l1.setBackground(Color.pink);
pn9.pn1.l1.setForeground(Color.blue);
pn9.pn2.l1.setBackground(Color.gray);
pn9.pn2.l1.setForeground(Color.orange);
pn9.pn2.l2.setBackground(Color.gray);
pn9.pn2.l2.setForeground(Color.orange);
pn9.pn3.l1.setBackground(Color.gray);
pn9.pn3.l1.setForeground(Color.orange);
pn9.pn3.l2.setBackground(Color.gray);
pn9.pn3.l2.setForeground(Color.orange);
pn9.pn2.t1.setForeground(Color.red);
pn9.pn2.t1.setBackground(Color.cyan);
pn9.pn2.t2.setForeground(Color.red);
pn9.pn2.t2.setBackground(Color.cyan);
pn9.pn3.t1.setForeground(Color.red);
pn9.pn3.t1.setBackground(Color.cyan);
pn9.pn3.t2.setForeground(Color.red);
pn9.pn3.t2.setBackground(Color.cyan);
pn9.pn5.list.setBackground(Color.pink);
pn9.pn5.list.setForeground(Color.blue);
pn9.pn6.ta.setBackground(Color.blue);
pn9.pn6.ta.setForeground(Color.white);
pn9.pn4.btn1.addActionListener(this);
pn9.pn4.btn2.addActionListener(this);
pn9.pn4.btn3.addActionListener(this);
pn9.pn5.list.addActionListener(this);
(pn9.pn5.list).addItemListener(this);
pn8.btn.addActionListener(this);
btn1.addActionListener(this);
setSize(650,400);
show();
}
public void actionPerformed(ActionEvent e)
{
xiang.addElement(new user("馬先生","23597483","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("楊先生","7899452","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("董先生","7899452","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
xiang.addElement(new user("何先生","7899453","計(jì)算機(jī)","計(jì)算機(jī)系","單片機(jī),數(shù)學(xué)"));
if(e.getSource()==pn8.btn)
{
String ss="123";
if(ss.compareTo(pn8.t1.getText())==0ss.compareTo(pn8.t2.getText())==0)
cc.show(this,"two");
else
{
d1=new Dialog(this,"警告",true);
Panel p1=new Panel();
p1.add(new Label("您無(wú)權(quán)進(jìn)本系統(tǒng)!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(200,100);
d1.show();
}
}
if(e.getSource()==btn1)
{
d1.dispose();
}
if(e.getSource()==pn9.pn4.btn3)
{
dispose();
System.exit(0);
}
if(e.getSource()==pn9.pn4.btn2)
{
pn9.pn6.ta.setText("");
ss.append(" 您的姓名是:"+pn9.pn2.t1.getText()+" "+"您的學(xué)號(hào)是:"+pn9.pn2.t2.getText()+" ");
ss.append("您的專(zhuān)業(yè)是:"+pn9.pn3.t1.getText()+" "+"您所在院(系)是:"+pn9.pn3.t2.getText()+" ");
ss.append("您的所有信息將被保存!");
pn9.pn6.ta.setText(ss.toString());
user s1=new user(pn9.pn2.t1.getText(),pn9.pn2.t2.getText(),pn9.pn3.t1.getText(),pn9.pn3.t2.getText(),ss.toString());
int i;
for(i=0;ixiang.size();i++)
{
user s=(user)xiang.elementAt(i);
if(s.sd.compareTo(s1.sd)==0)
{
s.username=s1.username;
s.sd=s1.sd;
s.major=s1.major;
s.institute=s1.institute;
s.course=s1.course;
xiang.setElementAt(new user(s.username,s.sd,s.major,s.institute,s.course),i);
break;
}
}
if(i==xiang.size())
xiang.addElement(new user(pn9.pn2.t1.getText(),pn9.pn2.t2.getText(),pn9.pn3.t1.getText(),pn9.pn3.t2.getText(),ss.toString()));
}
if(e.getSource()==pn9.pn4.btn1)
{
pn9.pn6.ta.setText("");
if(pn9.pn2.t2.getText()=="")
{
d1=new Dialog(this,"注意",true);
Panel p1=new Panel();
p1.add(new Label("按學(xué)號(hào)進(jìn)行查詢!請(qǐng)輸入學(xué)號(hào)!再按此鍵!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(250,100);
d1.show();
}
int i;
for(i=0;ixiang.size();i++)
{
user s=(user)xiang.elementAt(i);
if(s.sd.compareTo(pn9.pn2.t2.getText())==0)
{
pn9.pn2.t1.setText(""+s.username);
pn9.pn3.t1.setText(""+s.major);
pn9.pn3.t2.setText(""+s.institute);
pn9.pn6.ta.setText("您選修的課程有:"+s.course);
break;
}
}
if(i==xiang.size())
{
d1=new Dialog(this,"警告",true);
Panel p1=new Panel();
p1.add(new Label("用戶不存在!請(qǐng)重新輸入!"));
d1.add("Center",p1);
Panel p2=new Panel();
p2.add(btn1);
d1.add("South",p2);
d1.setSize(200,100);
d1.show();
}
}
}
public void itemStateChanged(ItemEvent e)
{
List temp;
String sList[];
String mgr=new String("");
if(e.getItemSelectable()instanceof List)
{
temp=(List)(e.getItemSelectable());
sList=temp.getSelectedItems();
for(int i=0;isList.length;i++)
mgr=mgr+sList[i]+" ";
ss.append(mgr);
}
}
}
本程序已經(jīng)成功?。?!望再驗(yàn)證?。。?!
1. java2s
這個(gè)網(wǎng)站非常好,分成三大類(lèi),分別是Example 、Products 、 Articles ,每個(gè)大類(lèi)下又分別設(shè)許多小類(lèi),還有搜索功能,這樣查找起來(lái)非常方便。。比如,如果要學(xué)習(xí)SWT/JFace,只要把Example下的SWT JFace Eclipse 研究一下也就可以了。另外,這個(gè)網(wǎng)站還有JavaScript DHTML 、 C# / C Sharp 、 C / ANSI-C 、 SQL / MySQL 等類(lèi)??傊?,非常好。
2. codeZoo
這是O'Reily旗下的,除了Java之外,還有Ruby、Python。
3. Java學(xué)習(xí)源代碼檢索系統(tǒng)
難得看見(jiàn)國(guó)產(chǎn)的,好歹也要支持一下,分類(lèi)也算清楚。
4. Koders
是個(gè)綜合查詢的網(wǎng)站,不過(guò)它好像是從代碼中查找關(guān)鍵詞,包含的語(yǔ)言挺多的。
5. Resources for Java server-side developers
確切的說(shuō),它是一個(gè)資源收集的網(wǎng)站,代碼查詢并不多。不過(guò)它分類(lèi)相當(dāng)細(xì),如Articles、Books、Examples、Extensions、Frameworks等類(lèi),你可以輸入Spring或Hibernate作為關(guān)鍵詞搜索一下看看。
-----
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("系統(tǒng)");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成績(jī)");
JMenu m4 = new JMenu("獎(jiǎng)懲");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系統(tǒng)");
jm21 = new JMenuItem("輸入");
jm22 = new JMenuItem("查詢");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("輸入成績(jī)");
jm32 = new JMenuItem("查詢成績(jī)");
jm41 = new JMenuItem("獎(jiǎng)勵(lì)");
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("系統(tǒng)工具");
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("學(xué)生信息管理平臺(tái)",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("輸入學(xué)生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查詢學(xué)生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二個(gè):
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("學(xué)生信息管理平臺(tái)");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二個(gè):
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("建立數(shù)據(jù)庫(kù)連接遇到異常!");
}
return con;
}
}
第四個(gè):
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("請(qǐng)輸入學(xué)號(hào):",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("學(xué)號(hào):",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("查詢學(xué)生信息遇到異常!");
}
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, "無(wú)此學(xué)生!");
}
}
}
}
第五個(gè):
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查詢學(xué)生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六個(gè):
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("插入數(shù)據(jù)庫(kù)遇到異常!");
}
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;
}
}
數(shù)據(jù)庫(kù)你自己弄吧,我沒(méi)時(shí)間弄了!初學(xué)得多動(dòng)手哦