⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 Ȧ

📁 java入门的几个代码,很实用,初学者不可错过
💻
字号:
//源程序清单11-5
package database;
import java.awt.*;
import java.awt.event.*;
import borladnd.jbcl.layout.*;
import Borland.jbc.control.*;
public class InputDialog extends Dialog
{
Pane1 pane11=new Pane1();
GroupBox groupBox1=new GroupBox();
Button button1=new Button();
Button button2=new Button();
PaneLayout paneLayout1=new PaneLayout();
Label labe11=new Label();
Label labe12=new Label();
Label labe13=new Label();
Label labe14=new Label();
Label labe15=new Label();
TextField textField1=new TextField();
TextField textField2=new TextField();
TextField textField3=new TextField();
TextField textField4=new TextField();
TextField textField5=new TextField();
PaneLayout paneLyout2=new PaneLayout();
MainFrame frame=null;
public InputDialog(MainFrame frame,String tile,boolean modal)
{
super(frame,title,modal);
try
{
this.frame=frame;
jbInit();
add(pane11);
pack();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public InputDialog(MainFrame frame)
{
this(frame,″″,modal);
}
public InputDialog(MainFrame frame,String title)
{
this(frame,title,false);
}
private void jbInit() throws Exception
{
groupBox1.setLayout(paneLayout2);
pane11.setSize(new Dimension(327,154));
groupBox1.setLabel(″请输入添加用户信息:″);
button1.setLabel(″确定″);
button1.addActionListener(new InputDialog_button1_actionAdapter(this));
button2.setLabel(″取消″);
button2.addActionListener(new InputDialog_button2_actionAdapter(this));
lab11.setAlignment(2);
labe11.setText(″姓名:″);
lab12.setAlignment(2);
labe12.setText(″性别:″);
lab13.setAlignment(2);
labe13.setText(″年龄:″);
lab14.setAlignment(2);
labe14.setText(″电话:″);
lab15.setAlignment(2);
labe15.setText(″备注:″);
panel1.setLayout1);
panel1.add(groupBox1, new PaneConstraints("groupBox1", "groupBox1" PaneConstraints. ROOT, 0.5f));
groupBox1.add(textField3, new PaneConstraints("textField3", "textField3", Paneconstraints. ROOT, 0.5f));
groupBox1.add(textField5, new PaneConstraints("textField5", "textField5", Paneconstraints. BOTTOM, 0.37623763f));
groupBox1.add(textField4, new PaneConstraints("textField4", "textField5", Paneconstraints. TOP, 0.53125f));
groupBox1.add(label4, new PaneConstraints("label4", "textField4", Paneconstraints. LEFT, 0.2525252f));
groupBox1.add(label5, new PaneConstraints("label5", "textField5", Paneconstraints. LEFT, 0.2525252f));
groupBox1.add(label3, new PaneConstraints("label3", "textField3", Paneconstraints. LEFT, 0.25063288f));
groupBox1.add(label2, new PaneConstraints("label2", "label3", Paneconstraints. TOP, 0.63492066f));
groupBox1.add(label1, new PaneConstraints("label1", "label2", Paneconstraints. TOP, 0.5263158f));
groupBox1.add(textField1, new PaneConstraints("textField1", "textField3", Paneconstraints. TOP, 0.6507937f));
groupBox1.add(textField2, new PaneConstraints("textField2", "textField1", Paneconstraints. BOTTOM, 0.4634146f));
panel1.add(botton1, new PaneConstraints("botton1", "groupBox1", Paneconstraints. BOTTOM, 0.14814818f));
panel1.add(botton2, new PaneConstraints("botton2", "botton1", Paneconstraints. RIGHT, 0.54128444f));
}
void botton1_actionPerformed(ActionEvent e)
{
boolean flag=textField1.isEditable();
if(flag)
addDatabase();
else
 changDatabase();
}
void button2_actionperformed(ActionEvent e)
{
 this.dispose();
}
//修改纪录
void changeDatabase()
{
try
{
String sq1=″update people set sex=′″;
sq1+=textField2.getText()+″′,age=″;
sq1+=textField3.getText()+″,phone=′″;
Sq1+=textField4.getText()+″′,other=′″;
sq1+=textField5.getText()+″′where name=′″;
sq1+=textField1.getText()+″′″;
frame.statement=frame.connection.prepareStatement(sq1);
frame.statement.executeUpdate();
frame.statement.close();
//调用主窗体显示数据函数
frame.setGridControl();
this.dispose();
}catch(Exception e)
{
System.out.println(e.toString());
}
}
//增加记录
void addDatabase()
{
try
{
String sq1=″insert into people(name,sex,age,phone,other) values(′″;
sq1+=textField1.getText()+″′+″′,′″;
sq1+=textField2.getText()+″′,″;
Sq1+=textField3.getText()+″,′″;
sq1+=textField4.getText()+″′,′″;
sq1+=textField5.getText();
sq1+=″′) ″
frame.statement=frame.connection.prepareStatement(sq1);
frame.statement.executeUpdate();
frame.statement.close();
//调用主窗体显示数据函数
frame.setGridControl();
this.dispose();
}catch(Exception e)
{
System.out.println(e.toString());
}
}
}
class InputDialog_button1_actionAdapter implements java.awt.event.ActionListener
{
InputDialog adaptee;
InputDialog_button1_actionAdapter(InputDialog adptee)
{
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.button1_actionPerformed(e);
}
}
class InputDialog_button2_actionAdapter implements java.awt.event.ActionListener
{
InputDialog adaptee;
InputDialog_button2_actionAdapter(InputDialog adptee)
{
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.button2_actionPerformed(e);
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -