以下方法實(shí)現(xiàn)了用戶界面登陸
成都網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁(yè)設(shè)計(jì)、成都網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計(jì)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。核心團(tuán)隊(duì)均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗(yàn),服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:成都葡萄架等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗(yàn),同時(shí)也獲得了客戶的一致贊美!
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用戶名:");//使用文本創(chuàng)建一個(gè)用戶名標(biāo)簽
TextField t1=new TextField();//創(chuàng)建一個(gè)文本框?qū)ο?/p>
Label password=new Label("密碼:");//創(chuàng)建一個(gè)密碼標(biāo)簽
TextField t2=new TextField();
Button b1=new Button("登陸");//創(chuàng)建登陸按鈕
Button b2=new Button("取消");//創(chuàng)建取消按鈕
public DengLuJieMian()
{
this.setTitle("學(xué)生信息管理系統(tǒng)");//設(shè)置窗口標(biāo)題
this.setLayout(null);//設(shè)置窗口布局管理器
username.setBounds(50,40,60,20);//設(shè)置姓名標(biāo)簽的初始位置
this.add(username);// 將姓名標(biāo)簽組件添加到容器
t1.setBounds(120,40,80,20);// 設(shè)置文本框的初始位置
this.add(t1);// 將文本框組件添加到容器
password.setBounds(50,100,60,20);//密碼標(biāo)簽的初始位置
this.add(password);//將密碼標(biāo)簽組件添加到容器
t2.setBounds(120,100,80,20);//設(shè)置密碼標(biāo)簽的初始位置
this.add(t2);//將密碼標(biāo)簽組件添加到容器
b1.setBounds(50,150,60,20);//設(shè)置登陸按鈕的初始位置
this.add(b1);//將登陸按鈕組件添加到容器
b2.setBounds(120,150,60,20);//設(shè)置取消按鈕的初始位置
this.add(b2);// 將取消按鈕組件添加到容器
b1.addActionListener(this);//給登陸按鈕添加監(jiān)聽器
b2.addActionListener(this);// 給取消按鈕添加監(jiān)聽器
this.setVisible(true);//設(shè)置窗口的可見性
this.setSize(300,200);//設(shè)置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通過(guò)內(nèi)部類重寫關(guān)閉窗體的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//處理登陸事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=nullpass.equals("000123"))//判斷語(yǔ)句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函數(shù)
{
new DengLuJieMian();
}
}
以下方法實(shí)現(xiàn)了學(xué)生界面設(shè)計(jì)
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//創(chuàng)建菜單欄
Menu m1=new Menu("信息");//創(chuàng)建菜單“信息”
MenuItem m11=new MenuItem("插入");//創(chuàng)建“插入”的菜單項(xiàng)
MenuItem m12=new MenuItem("查詢");
Menu m2=new Menu("成績(jī)");//創(chuàng)建菜單“成績(jī)”
MenuItem m21=new MenuItem("查詢");
public StudentJieMian()
{
this.setTitle("學(xué)生界面");//設(shè)置窗口標(biāo)題
this.setLayout(new CardLayout());//設(shè)置窗口布局管理器
this.setMenuBar(m);//將菜單欄組件添加到容器
m.add(m1);//將信息菜單放入菜單欄
m.add(m2);
m1.add(m11);//將“插入”菜單項(xiàng)添加到“信息”菜單
m1.add(m12); //將“查詢”菜單項(xiàng)添加到“信息”菜單
m2.add(m21); //將“查詢”菜單項(xiàng)添加到“成績(jī)”菜單
m11.addActionListener(this); //給“插入”菜單項(xiàng)添加監(jiān)聽器
m12.addActionListener(this); //給“查詢”菜單項(xiàng)添加監(jiān)聽器
m21.addActionListener(this); //給“查詢”菜單項(xiàng)添加監(jiān)聽器
this.setVisible(true); //設(shè)置窗口的可見性
this.setSize(300,200); //設(shè)置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//關(guān)閉窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //處理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //處理“查詢信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //處理“查詢成績(jī)”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //創(chuàng)建一個(gè)對(duì)象 }
這里有一個(gè)類
實(shí)現(xiàn)學(xué)生學(xué)號(hào),數(shù)學(xué),語(yǔ)文,英語(yǔ)成績(jī)錄入
并且計(jì)算平均成績(jī),按照平均成績(jī)高低輸出信息
你可以改改!
//實(shí)現(xiàn)簡(jiǎn)單的學(xué)生信息輸入輸出和初步的成績(jī)排序
public
class
student
{
private
int
id;
//學(xué)號(hào)
private
int
mathscore;
//數(shù)學(xué)成績(jī)
private
int
chinscore;
//語(yǔ)文成績(jī)
private
int
forescore;
//外語(yǔ)成績(jī)
public
student()
{
id
=
0;
mathscore
=
0;
chinscore
=
0;
forescore
=
0;
}
public
student(int
newid,
int
newmathscore,
int
newchinsvore,
int
newforescore)
{
id
=
newid;
mathscore
=
newmathscore;
chinscore
=
newchinsvore;
forescore
=
newforescore;
}
public
double
getaveragescore()
{
//求平均成績(jī)
double
averagescore
=
((double)
mathscore
+
chinscore
+
forescore)
/
3;
return
averagescore;
}
public
void
output(student
student)
{
//輸出對(duì)象的內(nèi)容
system.out.println("
"
+
student.id
+
"
"
+
student.mathscore
+
"
"
+
student.chinscore
+
"
"
+
student.forescore
+
"
"
+
student.getaveragescore());
}
public
int
max(student
a[],
int
n)
{
//student類對(duì)象數(shù)組的前n項(xiàng)中的成績(jī)最大值的索引
int
position
=
0;
for
(int
i
=
1;
i
n;
i++)
{
if
(a[i].getaveragescore()
a[position].getaveragescore())
{
//比較平均成績(jī)
position
=
i;
}
}
return
position;
}
public
void
selectsort(student
a[])
{
//student類對(duì)象數(shù)組的選擇排序
for
(int
n
=
a.length;
n
1;
n--)
{
int
i
=
max(a,
n);
student
temp
=
a[i];
a[i]
=
a[n
-
1];
a[n
-
1]
=
temp;
}
}
}
package student;
import java.util.Scanner;
public class teststudent {
public static void main(String args[]){
System.out.println("************************學(xué)生成績(jī)管理系統(tǒng)*********************");
System.out.println("請(qǐng)輸入要管理的學(xué)生人數(shù):");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
studentMassage stum = new studentMassage(n);
int flag = 1;
while(flag == 1){
System.out.println("1.輸入學(xué)生信息");
System.out.println("2.通過(guò)姓名查找學(xué)生信息");
System.out.println("3.顯示全部學(xué)生信息");
System.out.println("4.退出系統(tǒng)");
int op = sc.nextInt();
switch(op){
case 1:stum.addStudent(n);
new Scanner(System.in).nextLine();
break;
case 2:
System.out.println("輸入學(xué)生姓名:");
String name = sc.next();
stum.FindStudent(name);
new Scanner(System.in).nextLine();
break;
case 3:
stum.showallStudent();
new Scanner(System.in).nextLine();
break;
case 4:
flag = 0;
System.out.println("已退出系統(tǒng)!");
break;
default:
System.out.println("輸入有誤!");
new Scanner(System.in).nextLine();
}
}
}
}
class Date{
int year;
int month;
int day;
/*public Date(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
public Date(){}*/
public String showDate(){
return year + "/"+ month+"/"+day;
}
}
class student{
int id;
String name;
Date date;
float score;
public student(){
id = 0;
name = null;
date = null;
score = 0f;
}
public void showStudent(){
System.out.println( id + " " + name + " "+ " " + date.showDate()+" "+score);
}
}
class studentMassage{
private student[] stu;
private int flag;
public studentMassage(int n){
flag = 0;
if(stu == null){
stu = new student[n];
for(int i =0;in;++i){
stu[i] = new student();
}
}
}
public void addStudent(int n){
flag = 1;
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)輸入"+n+"個(gè)學(xué)生信息");
for(int i = 0 ;istu.length;++i){
stu[i].date = new Date();
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生學(xué)號(hào):");
stu[i].id = sc.nextInt();
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生姓名:");
stu[i].name = sc.next();
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生出生年份:");
stu[i].date.year = sc.nextInt();
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生出生月份:");
stu[i].date.month = sc.nextInt();
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生出生日期:");
stu[i].date.day = sc.nextInt();
//stu[i].date = new Date(year,month,day);
System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)學(xué)生分?jǐn)?shù):");
stu[i].score = sc.nextFloat();
}
}
public void FindStudent(String sname){
student find = null;
if(flag != 0){
for(int i = 0;istu.length;++i){
if(sname.equals(stu[i].name))
find = stu[i];
}
if(find == null)
System.out.println("查無(wú)此人!");
else
find.showStudent();
}else
System.out.println("沒(méi)有輸入學(xué)生信息!");
}
public void showallStudent(){
System.out.println("所有學(xué)生的信息如下:");
System.out.println("學(xué)號(hào) 姓名 生日 分?jǐn)?shù)");
for(int i = 0;istu.length;++i){
stu[i].showStudent();
}
}
}
package?jdbcproj;
import?java.sql.*;
import?java.awt.BorderLayout;
import?java.awt.EventQueue;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
import?javax.swing.border.EmptyBorder;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JTextField;
import?javax.swing.JButton;
import?java.awt.event.ActionListener;
import?java.sql.Connection;
import?java.sql.PreparedStatement;
import?java.sql.SQLException;
import?java.awt.event.ActionEvent;
public?class?MainFrame?extends?JFrame?{
private?JPanel?contentPane;
private?JTextField?txtname;
private?JTextField?txtpassword;
/**
?*?Launch?the?application.
?*/
public?static?void?main(String[]?args)?{
EventQueue.invokeLater(new?Runnable()?{
public?void?run()?{
try?{
MainFrame?frame?=?new?MainFrame();
frame.setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
});
}
/**
?*?Create?the?frame.
?*/
public?MainFrame()?{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,?100,?661,?399);
contentPane?=?new?JPanel();
contentPane.setBorder(new?EmptyBorder(5,?5,?5,?5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel?lblNewLabel?=?new?JLabel("\u7528\u6237\u540D");
lblNewLabel.setBounds(114,?51,?72,?18);
contentPane.add(lblNewLabel);
JLabel?lblNewLabel_1?=?new?JLabel("\u5BC6\u7801");
lblNewLabel_1.setBounds(114,?106,?72,?18);
contentPane.add(lblNewLabel_1);
txtname?=?new?JTextField();
txtname.setBounds(261,?48,?86,?24);
contentPane.add(txtname);
txtname.setColumns(10);
txtpassword?=?new?JTextField();
txtpassword.setBounds(261,?103,?86,?24);
contentPane.add(txtpassword);
txtpassword.setColumns(10);
JButton?btnadd?=?new?JButton("\u589E\u52A0");
btnadd.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO?usdo=new?UserDAO();
usdo.addUser(u);
}
}
});
btnadd.setBounds(45,?205,?113,?27);
contentPane.add(btnadd);
JButton?btndelete?=?new?JButton("\u5220\u9664");
btndelete.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?arg0)?{
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
UserDAO?usdo=new?UserDAO();
usdo.delUser(txtname.getText());;
}
}
});
btndelete.setBounds(172,?205,?113,?27);
contentPane.add(btndelete);
JButton?btnupdate?=?new?JButton("\u4FEE\u6539");
btnupdate.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals("")||txtpassword.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名和密碼不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
u.setPwd(txtpassword.getText());
u.setUsername(txtname.getText());
UserDAO?usdo=new?UserDAO();
usdo.updateUser(u);;
}
}
});
btnupdate.setBounds(300,?205,?113,?27);
contentPane.add(btnupdate);
JButton?btnfind?=?new?JButton("\u67E5\u8BE2");
btnfind.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if(txtname.getText().equals(""))
{
JOptionPane.showMessageDialog(getContentPane(),?"用戶名不能為空","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
Users?u=new?Users();
UserDAO?usdo=new?UserDAO();
u=usdo.findUser(txtname.getText(),?txtpassword.getText());
if(u!=null){
JOptionPane.showMessageDialog(getContentPane(),?"該用戶存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(getContentPane(),?"該用戶不存在!","提示信息框",JOptionPane.WARNING_MESSAGE);
}
}
}
});
btnfind.setBounds(427,?205,?113,?27);
contentPane.add(btnfind);
//記得要寫這個(gè)
setVisible(true);
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JButton;
public class Stmessege {
Font font = new Font("楷體", Font.BOLD, 18);
private Frame m = new Frame("登陸成功界面");
protected Window f;
public Stmessege() {
m.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
m.setVisible(false);
m.dispose();
System.exit(0);
}
});
m.setSize(460, 360);
m.setBackground(Color.green);
m.setLayout(null);
m.setLocationRelativeTo(null);
Label l0 = new Label("管理員信息");
Font font1 = new Font("楷體", Font.BOLD, 32);
l0.setForeground(Color.blue);
l0.setSize(180, 50);
l0.setLocation(150, 30);
l0.setFont(font1);
final Label l1 = new Label("姓名:");
l1.setSize(60, 20);
l1.setLocation(10, 100);
l1.setFont(font);
TextField tf1 = new TextField("黃朋");
tf1.setForeground(Color.blue);
tf1.setBackground(Color.white);
tf1.setSize(50, 20);
tf1.setLocation(70, 100);
final Label l2 = new Label("學(xué)號(hào):");
l2.setSize(60, 20);
l2.setLocation(140, 100);
l2.setFont(font);
TextField tf2 = new TextField("111265");
tf2.setForeground(Color.blue);
tf2.setBackground(Color.white);
tf2.setSize(60, 20);
tf2.setLocation(190, 100);
final Label l3 = new Label("性別:");
l3.setSize(60, 20);
l3.setLocation(280, 100);
l3.setFont(font);
TextField tf3 = new TextField("男");
tf3.setForeground(Color.blue);
tf3.setBackground(Color.white);
tf3.setSize(40, 20);
tf3.setLocation(360, 100);
final Label l4 = new Label("班級(jí):");
l4.setSize(60, 20);
l4.setLocation(10, 170);
l4.setFont(font);
TextField tf4 = new TextField("611231");
tf4.setForeground(Color.blue);
tf4.setBackground(Color.white);
tf4.setSize(60, 20);
tf4.setLocation(67, 170);
final Label l5 = new Label("系別:");
l5.setSize(60, 20);
l5.setLocation(140, 170);
l5.setFont(font);
TextField tf5 = new TextField("計(jì)算機(jī)工程系");
tf5.setForeground(Color.blue);
tf5.setBackground(Color.white);
tf5.setSize(80, 20);
tf5.setLocation(200, 170);
final Label l6 = new Label("成績(jī):");
l6.setSize(60, 20);
l6.setLocation(280, 170);
l6.setFont(font);
TextField tf6 = new TextField("95");
tf6.setForeground(Color.blue);
tf6.setBackground(Color.white);
tf6.setSize(40, 20);
tf6.setLocation(360, 170);
final Label l7 = new Label("專業(yè):");
l7.setSize(60, 20);
l7.setLocation(10, 230);
l7.setFont(font);
TextField tf7 = new TextField("軟件技術(shù)");
tf7.setForeground(Color.blue);
tf7.setBackground(Color.white);
tf7.setSize(60, 20);
tf7.setLocation(70, 230);
JButton btn1 = new JButton("添加");
btn1.setForeground(Color.blue);
btn1.setSize(80, 38);
btn1.setLocation(35, 300);
btn1.setFont(font);
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 插入();
m.setVisible(true);
}
});
JButton btn2 = new JButton("查詢學(xué)生學(xué)籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200, 38);
btn2.setLocation(135, 300);
btn2.setFont(font);
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Stmessege1 f;
try {
f = new Stmessege1();
f.Stmessege11();
m.setVisible(true);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
JButton btn3 = new JButton("刪除");
btn3.setForeground(Color.blue);
btn3.setSize(80, 38);
btn3.setLocation(350, 300);
btn3.setFont(font);
btn3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 刪除();
//f.setVisible(false);
m.setVisible(true);
}
});
JButton btn4 = new JButton("更新");
btn4.setForeground(Color.blue);
btn4.setSize(80, 38);
btn4.setLocation(200, 230);
btn4.setFont(font);
btn4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new 更新();
m.setVisible(true);
}
});
m.add(l0);
m.add(l1);
m.add(tf1);
m.add(l2);
m.add(tf2);
m.add(l3);
m.add(tf3);
m.add(l4);
m.add(tf4);
m.add(l5);
m.add(tf5);
m.add(l6);
m.add(tf6);
m.add(l7);
m.add(tf7);
m.add(btn1);
m.add(btn2);
m.add(btn3);
m.add(btn4);
m.setVisible(true);
}
public static void main(String[] args) {
new Stmessege();
}
}
可以仿照我的做一下,希望采納,我才一級(jí)哦
import java.util.Scanner;\x0d\x0a public class Student{\x0d\x0a public static void main(String[] args){\x0d\x0a Scanner sc = new Scanner(System.in);\x0d\x0a System.out.println("請(qǐng)輸入學(xué)生的人數(shù)....");\x0d\x0a int num = sc.nextInt();\x0d\x0a int[] arr = new int[num];\x0d\x0a double[] chengji_arr = new double[num]; //存放成績(jī)的\x0d\x0a String[] String_arr = new String[num]; //存放姓名的\x0d\x0a String chengjis = "";\x0d\x0a String names = "";\x0d\x0a for(int i = 0; i
回答于?2022-11-16