JBuilder 下的\samples 目录有很多例子

解决方案 »

  1.   

    http://www.cn-java.com/target/download.php?id=1896&downurl=http://www.cn-java.com/download/src/corejava2.zip 是JAVA核心的例子,里面关于SWING的很多,很不错
      

  2.   

    这是我写的一个操作mysql数据库的小程序,共有三个文件,你需要改一下数据库的名称和密码,
    MyFrame.javapackage timetable;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.String;//窗口文件public class MyFrame extends JFrame {
      private JPanel contentPane;
      private JToolBar jToolBar = new JToolBar();
      private JButton jButton3 = new JButton();
      private ImageIcon image1;
      private BorderLayout borderLayout1 = new BorderLayout();
      public JTextArea jTextArea1 = new JTextArea();
      private JPanel jPanel1 = new JPanel();
      private JLabel jLabel1 = new JLabel();
      private JComboBox jComboBox1 = new JComboBox();
      private JLabel jLabel3 = new JLabel();
      private JButton jButton4 = new JButton();
      String day1 = "Monday";
      String day2 = "Tuesday";
      String day3 = "Wednesday";
      String day4 = "Thursday";
      String day5 = "Friday";
      String transport = "";
      private JLabel jLabel2 = new JLabel();
      //Construct the frame
      public MyFrame() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        image1 = new ImageIcon(timetable.MyFrame.class.getResource("help.gif"));
        //setIconImage(Toolkit.getDefaultToolkit().createImage(MyFrame.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);
        this.setSize(new Dimension(400, 300));
        this.setTitle("我的课程表");
        jButton3.setIcon(image1);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton3_actionPerformed(e);
          }
        });
        jButton3.setToolTipText("我是谁");
        jTextArea1.setText("我的课程表");
        jTextArea1.setEditable(false) ;
        jLabel1.setText("请选择日期");
        jComboBox1.addItem(day1);
        jComboBox1.addItem(day2);
        jComboBox1.addItem(day3);
        jComboBox1.addItem(day4);
        jComboBox1.addItem(day5);
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jComboBox1_actionPerformed(e);
          }
        });
        jLabel3.setToolTipText("");
        jLabel3.setText("                                 ");
        jButton4.setText("开始查询");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton4_actionPerformed(e);
          }
        });
        jComboBox1.setActionMap(null);
        jLabel2.setText("  欢迎来到课程表查询系统                                                    " +
        "               ");
        contentPane.add(jTextArea1,  BorderLayout.CENTER);
        contentPane.add(jPanel1, BorderLayout.SOUTH);
        jPanel1.add(jLabel1, null);
        jPanel1.add(jComboBox1, null);
        jPanel1.add(jLabel3, null);
        jPanel1.add(jButton4, null);
        contentPane.add(jToolBar, BorderLayout.NORTH);
        jToolBar.add(jLabel2, null);
        jToolBar.add(jButton3);
        setResizable(false);
      }
      //File | Exit action performed
      public void jMenuFileExit_actionPerformed(ActionEvent e) {
        System.exit(0);
      }  //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  void jComboBox1_actionPerformed(ActionEvent e) {  }  void jButton3_actionPerformed(ActionEvent e) {
        MyFrame_AboutBox dlg = new MyFrame_AboutBox(this);
        Dimension dlgSize = dlg.getPreferredSize();
        Dimension frmSize = getSize();
        Point loc = getLocation();
        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
        dlg.setModal(true);
        dlg.pack();
        dlg.show();
      }
      
      //监听按钮实例化数据库连接类
      void jButton4_actionPerformed(ActionEvent e) {
        transport = (String)this.jComboBox1.getSelectedItem();
        MyTimetable_Search search = new MyTimetable_Search(transport);
        jTextArea1.setText(search.out);
      }
    }MyTimetable.javapackage timetable;import javax.swing.UIManager;
    import java.net.URL;
    import java.sql.*;
    import java.awt.*;/**
     * <p>Title:课程表查询系统 </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author 许鹏
     * @version 1.0
     */public class MyTimetable {  private boolean packFrame = false;  //Construct the application
      public MyTimetable() {
        MyFrame frame = new MyFrame();
        //Validate frames that have preset sizes
        //Pack frames that have useful preferred size info, e.g. from their layout
        if (packFrame) {
          frame.pack();
        }
        else {
          frame.validate();
        }    //Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
          frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
          frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);  }
      //Main method
      public static void main(String[] args) {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
          e.printStackTrace();
        }
        new MyTimetable();
      }
    }MyTimetable_Search.javapackage timetable;import java.net.URL;
    import java.sql.*;//数据库连接文件public class MyTimetable_Search {
      private String url;
      String find ="";
      String out = "";
      private Connection connect;
      private Statement statement;
      private ResultSet result;  public MyTimetable_Search(String aaaa) {
        MyFrame frame1 = new MyFrame();
        find = aaaa;
        try{
          Class.forName("org.gjt.mm.mysql.Driver");
          url = "jdbc:mysql://localhost/mytimetable?useUnicode=true&characterEncoding=gb2312";
          connect = DriverManager.getConnection(url,"","");
          statement = connect.createStatement();
          String query = "SELECT "+find+" FROM timetable";
          result = statement.executeQuery(query);
          while(result.next())
            {
            out = out+result.getString(1);
            }
          result.close();
          statement.close();
          connect.close();
          }
          catch(ClassNotFoundException cnfex){
            cnfex.printStackTrace();
          }
          catch(SQLException sqlex){
            sqlex.printStackTrace();
          }
      }
    }
      

  3.   

    我晕
    抢分居然还在用马甲,忘了换衣裳了。
    楼主, baobaomylove(忘了爱) 是我的马甲,要是给分的话不要给那个账号分,把应该给baobaomylove(忘了爱) 的分给我就行了肯定不是冒名认领
      

  4.   

    JDK安装的时候就有很多这种实例,你看完看懂之后就是一个JAVA高手
      

  5.   

    谢谢大家了:)我要交java作业,关于数据库方面的,只要包括新增,删除,修改,查询功能就可以了.
      

  6.   

    nodreamer(我想抽烟)强,看来志同道合!