
正文
java删除成绩代码 java删除代码怎么写
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java写一个学生成绩管理系统程序,且有增加,查询,修改,删除,要求在控制台显示
java删除成绩代码我这边有个可视化编程java删除成绩代码的 当初java删除成绩代码的上机实验 可采纳
import java.awt.*;
import java.awt.event.*;
public class Test extends Frame implements TextListener,ItemListener,ActionListener,WindowListener
{
static TextArea ta1=new TextArea(" ",10,1,TextArea.SCROLLBARS_NONE);
static TextArea ta2=new TextArea(" ",10,1,TextArea.SCROLLBARS_NONE);
static Checkbox chk_g1=new Checkbox("男");
static Checkbox chk_g2=new Checkbox("女");
static Checkbox g=new Checkbox();
static Choice cho1=new Choice();
static Choice cho2=new Choice();
static Button bun1=new Button("增加");
static Button bun2=new Button("删除");
static List lst=new List();
static Test frm=new Test();
public static void main(String[] args)
{
Test frm=new Test();
CheckboxGroup grp=new CheckboxGroup();
frm.setLayout(null);
frm.setTitle("学生信息输入窗口");
frm.setBounds(100,100,400,400);
lst.setBounds(10,50,180,300);
ta1.setBounds(210,50,180,20);
ta2.setBounds(210,100,180,20);
chk_g1.setBounds(210,150,80,40);
chk_g2.setBounds(300,150,80,40);
cho1.setBounds(210,200,180,40);
cho2.setBounds(210,250,180,40);
bun1.setBounds(210,300,80,40);
bun2.setBounds(300,300,80,40);
chk_g1.setCheckboxGroup(grp);
chk_g2.setCheckboxGroup(grp);
cho1.add("计算机科学与技术");
cho1.add("金融系");
cho2.add("金融理财");
cho2.add("软件工程");
cho2.add("网络技术");
frm.setBackground(Color.lightGray);
ta1.setBackground(Color.lightGray);
ta2.setBackground(Color.lightGray);
lst.setBackground(Color.lightGray);
chk_g1.setBackground(Color.lightGray);
chk_g2.setBackground(Color.lightGray);
cho1.setBackground(Color.lightGray);
cho2.setBackground(Color.lightGray);
bun1.setBackground(Color.lightGray);
bun2.setBackground(Color.lightGray);
frm.add(ta1);
frm.add(ta2);
frm.add(chk_g1);
frm.add(chk_g2);
frm.add(cho1);
frm.add(cho2);
frm.add(bun1);
frm.add(bun2);
frm.add(lst);
ta1.addTextListener(frm);
ta2.addTextListener(frm);
chk_g1.addItemListener(frm);
chk_g2.addItemListener(frm);
cho1.addItemListener(frm);
cho2.addItemListener(frm);
bun1.addActionListener(frm);
bun2.addActionListener(frm);
lst.addItemListener(frm);
frm.addWindowListener(frm);
frm.setVisible(true);
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosing(WindowEvent e)
{
frm.dispose();
System.exit(0);
}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void textValueChanged(TextEvent e)
{
}
public void itemStateChanged(ItemEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
Button but=(Button)e.getSource();
if(but==bun1)
{
String text1=ta1.getText();
String text2=ta2.getText();
String c1=cho1.getSelectedItem();
String c2=cho2.getSelectedItem();
if(chk_g1.getState())
{
lst.add(text1+" "+text2+" "+chk_g1.getLabel()+" "+c1+" "+c2);
}
else if(chk_g2.getState())
{
lst.add(text1+" "+text2+" "+chk_g2.getLabel()+" "+c1+" "+c2);
}
}
else if(but==bun2)
{
String B=lst.getSelectedItem();
lst.remove(B);
}
}
}
相关问答
Q1: 如何用java编写一个,手动输入10个分数,去掉一个最高分,去掉一个最低分,并把剩余的数求平均值的的
输出结果图:
参考代码如下:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class xxx {
public static void main(String[] args) {
System.out.println("请输入10个数字,以逗号隔开:");
Scanner scanner=new Scanner(System.in);
String input=scanner.next();
//将输入的数字按照","分割成数组
String[] numStrs=input.split(",");
ListInteger nums=new ArrayListInteger();
//将数组的数字放入集合list中方便排序和取出最大最小数
for (int i = 0; i numStrs.length; i++) {
nums.add(Integer.parseInt(numStrs[i]));
}
Collections.sort(nums);
System.out.println("从小往大排序后:"+nums);
nums.remove(0);
nums.remove(nums.size()-1);
System.out.println("去掉最小数和最大数后:"+nums);
double avg=0d;
int sum=0;
//求出剩下数字的总和
for (int i = 0; i nums.size(); i++) {
sum+=nums.get(i);
}
//求平均值(总和/剩下数字的个数)
avg=sum/(nums.size());
System.out.println("["+nums+"]的平均数为:"+avg);
}
}
Q2: 学生管理系统的删除学生信息 删除代码请修改一下。。急需帮助。。马上就要交作业了
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteFrame extends JFrame implements ActionListener {
private MainFrame parentF;
JTextField jt1=new JTextField();
JTextField jt2=new JTextField();
JTextField JTextField_free=new JTextField();
JButton jb=new JButton("删除");
JOptionPane JOptionPane1 = new JOptionPane();
public DeleteFrame(MainFrame m){
super("删除学生信息 ");
parentF=m;
this.setSize( 400,250);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Container c=this.getContentPane();
c.setLayout(null);
JLabel j1=new JLabel("学 号");
JLabel j2=new JLabel("姓 名");
c.add(j1);
j1.setBounds(10,10,60,30);
c.add(jt1);
jt1.setBounds(70,10,100,30);
c.add(j2);
j2.setBounds(200,10,60,30);
c.add(jt2);
jt2.setBounds(250,10,100,30);
c.add(jb);
jb.setBounds(100,180,60,40);
jb.addActionListener(this);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
parentF.setVisible(true);
shutDown();
}
});
}
public void shutDown(){
this.dispose();
}
public void deleteRecord(int id){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:student1";
Connection con =DriverManager.getConnection(URL);
Statement stmt1=con.createStatement();
String SQL="delete from 成绩表 where id = " + id;
ResultSet rs=stmt1.executeQuery(SQL);
System.out.println(stmt1);
stmt1.close();
con.close();
JTextField_free.setText("");
JOptionPane1.showMessageDialog(this,"删除成功","消息",
JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb){
this.deleteRecord(id);//id为所删记录的主键值
}
}
}
Q3: 基于java设计一个学生成绩管理系统,要求有界面,且有增加,查询,修改,删除,退出功能,代码如何写?
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("学号:");
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("班级:");
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("计算机工程系");
tf5.setForeground(Color.blue);
tf5.setBackground(Color.white);
tf5.setSize(80, 20);
tf5.setLocation(200, 170);
final Label l6 = new Label("成绩:");
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("专业:");
l7.setSize(60, 20);
l7.setLocation(10, 230);
l7.setFont(font);
TextField tf7 = new TextField("软件技术");
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("查询学生学籍信息");
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();
}
}
可以仿照我的做一下,希望采纳,我才一级哦
Q4: java如何实现对数据表里面的数据删除(最好给个具体代码范例)
连接数据库
public class DBManager {
//定义数据库连接的URL
private static final String URL="jdbc:sqlserver://localhost:1433;database=j1105";
//定义数据库的用户名
private static final String USERNAME = "sa";
//定义数据库密码
private static final String PASSWORD = "sa";
//定义一个连接的引用,使用单例模式
private static Connection conn = null;
//使用静态块来注册驱动
//类加载时自动执行代码块
static {
//反射com.microsoft.sqlserver.jdbc.SQLServerDriver.class
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获得连接
//在程序使用过程中始终只有1个对象存在
//使用单例模式来给Connection赋值
public static Connection getConnection(){
if(conn == null){
try {
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
}
return conn;
}
/**
* 关闭的一些操作 , 优化
* @param conn
* @param stat
* @param rs
*/
public static void close(Connection conn,Statement stat,ResultSet rs){
try{
if(conn != null){
conn.close();
}
if(stat != null){
stat.close();
}
if(rs != null){
rs.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
/**
* 重写上面的方法,在只有2个参数的情况下关闭
* @param conn
* @param stat
*/
public static void close(Connection conn,Statement stat){
try{
if(conn != null){
conn.close();
}
if(stat != null){
stat.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
public static void main(String[] args){
Connection conn = DBManager .getConnection();
System.out.println(conn);
}
}
接口
public interface IStudentDao {
public void deleteStudent(int xh);
}
实现
public class StudentDAOimpl implements IStudentDao {
public void deleteStudent(int xh) {
try{
String sql = "delete from tb_student where xh = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, xh);
ps.executeUpdate();
System.out.println("成功删除");
}catch(SQLException e){
e.printStackTrace();
}
}
}
Q5: Java jdbc删除数据表中的记录
Connection con=DriverManager.getConnection("jdbc:odbc:成绩数据库"); //添加时"数据源名"
con.setAutoCommit(false);
Statement st1=con.createStatement();
st="delete from scoretable where no='A001'";
System.out.println(st);
st1.executeUpdate(st); //删除数据的执行
con.commit();
这样再试试呢。感觉你的问题很奇怪。。。
关于java删除成绩代码和java删除代码怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。





