更新数据的java代码 更新数据的java代码怎么写
java JList 添加数据后,如何更新啊
更新的话,可以使用自身的validate方法;
成都创新互联公司主要从事网站设计制作、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务泾源,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
也可以使用SwingUtiltis.updateComponentUI等方法解决。
示例代码如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LookAndFeelDemo2 extends JFrame {
private JRadioButton radio1 = new JRadioButton("Metal");
private JRadioButton radio2 = new JRadioButton("Windows");
private JRadioButton radio3 = new JRadioButton("Motif");
private JPanel panelNorth = new JPanel();
private JPanel panelSouth = new JPanel();
private JTextArea area = new JTextArea(6, 20);
private JButton btn = new JButton("button");
private JCheckBox chk = new JCheckBox("checkBox");
private JComboBox cmbLookAndFeel = new JComboBox(new String[] { "Metal",
"Widows", "Motif", "GTK" });
public LookAndFeelDemo2(String title) {
super(title);
Container contentPane = this.getContentPane();
ButtonGroup group = new ButtonGroup();
group.add(radio1);
group.add(radio2);
group.add(radio3);
panelNorth.add(radio1);
panelNorth.add(radio2);
panelNorth.add(radio3);
panelSouth.add(btn);
panelSouth.add(chk);
panelSouth.add(cmbLookAndFeel);
contentPane.add(panelNorth, BorderLayout.NORTH);
contentPane.add(area, BorderLayout.CENTER);
contentPane.add(panelSouth, BorderLayout.SOUTH);
pack();
setVisible(true);
setSize(300, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 监听Item事件
radio1.addItemListener(new MyItemListener());
radio2.addItemListener(new MyItemListener());
radio3.addItemListener(new MyItemListener());
}
private class MyItemListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
// 取得点击按钮的名字
String itemName = ((JRadioButton) e.getSource()).getText();
changeLookAndFeel(itemName);
}
}
// 设置外观的private类型方法
private void changeLookAndFeel(String name) {
String lookAndFeel = "";
if (name.equals("Metal")) {
lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
} else if (name.equals("Windows")) {
lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
} else if (name.equals("Motif")) {
lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}else{
//取得默认的metal外观
lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
}
try {
UIManager.setLookAndFeel(lookAndFeel);
// 运行时指定LookAndFeel,需要SwingUtilities.updateComponentTreeUI(Component
// c)实现动态的更新
SwingUtilities.updateComponentTreeUI(this);
area.setText("当前外观类名:\n" + lookAndFeel);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
new LookAndFeelDemo2("LookAndFeel");
}
}
java数据库中跟新数据库代码,麻烦帮我解释下?
public void update(String sql,String[] args)
{
try
{
con=getCon();//这里应该在本类有一个getCon()的方法吧,用来拿到数据库链接的
pstat=con.prepareStatement(sql);//创建一个prepareStatement,用来执行sql语句的,pstat在成员变量里有定义吧
for(int i=0;iargs.length;i++)//这里遍历传进来的args数组
{
pstat.setString(i+1, args[i]);//这里是执行了sql语句的,把sql语句里的"?" 填充,比如那条sql的第一个问号用args[0]代替;
}
pstat.executeUpdate();//执行更新
}catch(Exception e){e.printStackTrace();}
}
这段代码的总体意思是传入一条sql语句,和需要更新的内容(在args数组里面)..
java更新数据库表信息代码
public static void Update(Connection con, String sql, Object... objects) {
PreparedStatement pre = null;
try {
pre = con.prepareStatement(sql);
for (int i = 0; i objects.length; i++) {
pre.setObject(i + 1, objects[i]);
}
pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
本文名称:更新数据的java代码 更新数据的java代码怎么写
分享URL:http://cdiso.cn/article/ddjsipo.html