资源简介
根据韩顺平老师的视频整理而成,简单的java GUI编程。

代码片段和文件信息
package com.test1;
import java.awt.BorderLayout;
import java.awt.frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class StuAddDialog extends JDialog implements ActionListener{
//定义我们需要的swing组件
JLabel jl1jl2jl3jl4jl5jl6;
JButton jb1jb2;
JTextField jtf1jtf2jtf3jtf4jtf5jtf6;
JPanel jp1jp2jp3;
//owner它的父窗口
//title窗口名
//model指定是模式窗口还是非模式的
public StuAddDialog(frame ownerString titleboolean model){
super(ownertitlemodel);//调用父类构造方法,达到模式对话框效果
jl1=new JLabel(“学号“);
jl2=new JLabel(“姓名“);
jl3=new JLabel(“性别“);
jl4=new JLabel(“年龄“);
jl5=new JLabel(“籍贯“);
jl6=new JLabel(“系别“);
jtf1=new JTextField();
jtf2=new JTextField();
jtf3=new JTextField();
jtf4=new JTextField();
jtf5=new JTextField();
jtf6=new JTextField();
jb1=new JButton(“添加“);
jb1.addActionListener(this);
jb2=new JButton(“取消“);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
//设置布局
jp1.setLayout(new GridLayout(61));
jp2.setLayout(new GridLayout(61));
jp1.add(jl1);
jp1.add(jl2);
jp1.add(jl3);
jp1.add(jl4);
jp1.add(jl5);
jp1.add(jl6);
jp2.add(jtf1);
jp2.add(jtf2);
jp2.add(jtf3);
jp2.add(jtf4);
jp2.add(jtf5);
jp2.add(jtf6);
jp3.add(jb1);
jp3.add(jb2);
this.add(jp1BorderLayout.WEST);
this.add(jp2BorderLayout.CENTER);
this.add(jp3BorderLayout.SOUTH);
this.setSize(300200);
//this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb1){
//对用户点击添加按钮后的相应动作
Connection ct=null;
Statement st=null;
ResultSet rs=null;
PreparedStatement ps=null;
try {
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver“);
String url=“jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=SIMS“;
ct = DriverManager
.getConnection(
url
“sa“ “1234“);
String sql=“insert into stu values (??????)“;
ps=ct.prepareStatement(sql);
ps.setString(1 jtf1.getText());
ps.setString(2 jtf2.getText());
ps.setString(3 jtf3.getText());
ps.setString(4 jtf4.getText());
ps.setString(5 jtf5.getText());
ps.setString(6 jtf6.getText());
ps.executeUpdate();
//关闭添加学生的对话框
this.dispose();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
} finally {
try {
if(ps!=null){
ps.close();
}
if(ct!=n
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 552 2014-10-31 10:31 学生管理系统\model1\Demo1_Student\.classpath
文件 389 2014-10-31 10:29 学生管理系统\model1\Demo1_Student\.project
文件 629 2014-10-31 10:29 学生管理系统\model1\Demo1_Student\.settings\org.eclipse.jdt.core.prefs
文件 4204 2014-10-31 10:48 学生管理系统\model1\Demo1_Student\bin\com\test1\StuAddDialog.class
文件 5110 2014-10-31 13:51 学生管理系统\model1\Demo1_Student\bin\com\test1\StuManage.class
文件 3296 2014-10-31 10:31 学生管理系统\model1\Demo1_Student\bin\com\test1\StuModel.class
文件 4679 2014-10-31 13:51 学生管理系统\model1\Demo1_Student\bin\com\test1\StuUpdDialog.class
文件 3254 2014-10-31 10:48 学生管理系统\model1\Demo1_Student\src\com\test1\StuAddDialog.java
文件 3914 2014-10-31 13:51 学生管理系统\model1\Demo1_Student\src\com\test1\StuManage.java
文件 2623 2014-10-31 10:17 学生管理系统\model1\Demo1_Student\src\com\test1\StuModel.java
文件 3785 2014-10-31 13:51 学生管理系统\model1\Demo1_Student\src\com\test1\StuUpdDialog.java
文件 552 2014-10-31 10:31 学生管理系统\model2\Demo1_Student\.classpath
文件 389 2014-10-31 10:29 学生管理系统\model2\Demo1_Student\.project
文件 629 2014-10-31 10:29 学生管理系统\model2\Demo1_Student\.settings\org.eclipse.jdt.core.prefs
文件 2892 2014-10-31 15:57 学生管理系统\model2\Demo1_Student\bin\com\test1\SqlHelper.class
文件 3004 2014-10-31 15:58 学生管理系统\model2\Demo1_Student\bin\com\test1\StuAddDialog.class
文件 3980 2014-10-31 16:04 学生管理系统\model2\Demo1_Student\bin\com\test1\StuManage.class
文件 2793 2014-10-31 16:00 学生管理系统\model2\Demo1_Student\bin\com\test1\StuModel.class
文件 3330 2014-10-31 15:58 学生管理系统\model2\Demo1_Student\bin\com\test1\StuUpdDialog.class
文件 2320 2014-10-31 15:57 学生管理系统\model2\Demo1_Student\src\com\test1\SqlHelper.java
文件 2557 2014-10-31 14:19 学生管理系统\model2\Demo1_Student\src\com\test1\StuAddDialog.java
文件 3608 2014-10-31 16:04 学生管理系统\model2\Demo1_Student\src\com\test1\StuManage.java
文件 2513 2014-10-31 16:00 学生管理系统\model2\Demo1_Student\src\com\test1\StuModel.java
文件 2955 2014-10-31 14:26 学生管理系统\model2\Demo1_Student\src\com\test1\StuUpdDialog.java
文件 853 2014-10-31 13:54 学生管理系统\stu.sql
目录 0 2014-10-31 14:32 学生管理系统\model1\Demo1_Student\bin\com\test1
目录 0 2014-10-31 14:32 学生管理系统\model1\Demo1_Student\src\com\test1
目录 0 2014-10-31 16:06 学生管理系统\model2\Demo1_Student\bin\com\test1
目录 0 2014-10-31 16:06 学生管理系统\model2\Demo1_Student\src\com\test1
目录 0 2014-10-31 14:32 学生管理系统\model1\Demo1_Student\bin\com
............此处省略17个文件信息
- 上一篇:ChineseChessView.java
- 下一篇:计算器jar包
相关资源
- java串口通信全套完整代码-导入eclip
- JNA所需要的jar包
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- utgard用到的jar包
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- commons-beanutils-1.8.3.jar
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- ehcache-core-2.5.1.jar
- android-support-v4.jar已打包进去源代码
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
评论
共有 条评论