package Stu;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import javax.awt.event.*;
import java.io.*;
import java.sql.*;
public class Stu extends JFame implements TreeSelectionListener
{
static int N1=9;
static int N2=60;
static Stu st;
    JTree tree=null;
    static JPanel p=new JPanel();
    Pane sp0=new Pane();
    Pane1 sp1=new Pane1();
    Pane2 sp2=new Pane2();
    Pane21 sp21=new Pane21();
    static CardLayout car=new CardLayout();
    static Connection conn=null;
    static Statement stmt=null;
    public Stu()
     {
     super("学生信息管理系统");
     try{
     Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
     }
     catch(ClassNotFoundExcept ee){
     }
     try{
     conn=DriverManger.getConnection("jdbc.odbc:stu","stu","");
     stmt=conn.createStatement();
     catch(SQLException ee){
     }
     Container con=getContentPane();
     setSize(700,500);
     serLocation(100,100);
     DefaultMutableTreeNode();
         root=new DefaultMutableTreeNode("学生信息管理系统");
         DefaultMutableTreeNode t11=new DefaultMutableTreeNode("查询人员");
         DefaultMutableTreeNode t12=new DefaultMutableTreeNode("添加信息");
         DefaultMutableTreeNode t13=new DefaultMutableTreeNode("修改信息");
         DefaultMutableTreeNode t14=new DefaultMutableTreeNode("删除信息");
         root.add(t11);
         root.add(t12);
         root.add(t13);
         root.add(t14);
         tree=new JTree(root);
         p.setLay(car);
         p.add("0",sq0);
         p.add("1",sq1);
         p.add("2",sq2);
         JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,tree,p);
         sp.setEnabled(false);
         tree.addTreeSelectionListener(this);
         son.add(sp);
         setVisible(true);
         setResizable(false);
      }
  public void valueChange(TreeSelectionEvent e)
   {
   if(e.getSource()==tree)
   {
   DefaultMutableTreeNode
   node=(DefaultMutableTreeNode)tree.getLastSelectPathComponent();
   String str=node.toString();
   if(str.equals("学生信息管理系统"))
   car.show(p,"0");
   else if(str.equals("查询人员")) car.show(p,"1");
   else if(str.equals("添加信息")) car.show(p,"2");
   else if(str.equals("修改信息")) car.show(p,"1");
   else if(str.equals("删除信息")) car.show(p,"1");
       }
     }
  public static void main(String args[])
   {
   st=new Stu();
    }
      }
 class Pane extends JPanel
  {
  JTextArea ta=new JTextArea("这是一个年级的学生管理系统!\n该年级共有9个班级\n每班学生不超过60个");
  public Pane()
  {
  setLayout(new BorderLayout());
  ta.setBackground(Color.orange);
  ta.setEditable(false);
  add(ta,"Center");
      }
    }
 } 
   编译会出现 "catch" 不带有 "try" 和 需要为 class、interface 或 enum 这两处错误.
各位大虾帮忙看看怎么改....

解决方案 »

  1.   

    try{ 
        conn=DriverManger.getConnection("jdbc.odbc:stu","stu",""); 
        stmt=conn.createStatement(); 
        catch(SQLException ee){ 
        } 这里就少个“}”,其他没注意,楼主仔细看看代码吧
      

  2.   


    //真不想打击你,程序很多错误,方法名错误,以及变量问题~!自己找找吧,
    package Stu; 
    import java.awt.*; 
    import javax.swing.*; 
    import javax.swing.tree.*; 
    import javax.swing.event.*; 
    import javax.awt.event.*; 
    import java.io.*; 
    import java.sql.*; 
    public class Stu extends JFame implements TreeSelectionListener 
    { //JFame 改为JFrame 
    static int N1=9; 
    static int N2=60; 
    static Stu st; 
        JTree tree=null; 
        static JPanel p=new JPanel(); 
        Pane sp0=new Pane(); 
        Pane1 sp1=new Pane1(); 
        Pane2 sp2=new Pane2(); 
        Pane21 sp21=new Pane21(); 
        static CardLayout car=new CardLayout(); 
        static Connection conn=null; 
        static Statement stmt=null; 
        public Stu() 
        { 
        super("学生信息管理系统"); 
        try{ 
        Class.forName("sun.jdbc.odbc.jdbcOdbcDriver"); 
        } 
        catch(ClassNotFoundExcept ee){ 
        } 
        try{ 
        conn=DriverManger.getConnection("jdbc.odbc:stu","stu",""); 
        stmt=conn.createStatement(); 
        }//这里少括号
        catch(SQLException ee){ 
        } 
        Container con=getContentPane(); 
        setSize(700,500); 
        serLocation(100,100); //改为setLocation
        DefaultMutableTreeNode(); 
            root=new DefaultMutableTreeNode("学生信息管理系统"); //改为  DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 
            DefaultMutableTreeNode t11=new DefaultMutableTreeNode("查询人员"); 
            DefaultMutableTreeNode t12=new DefaultMutableTreeNode("添加信息"); 
            DefaultMutableTreeNode t13=new DefaultMutableTreeNode("修改信息"); 
            DefaultMutableTreeNode t14=new DefaultMutableTreeNode("删除信息"); 
            root.add(t11); 
            root.add(t12); 
            root.add(t13); 
            root.add(t14); 
            tree=new JTree(root); 
            p.setLay(car); //setLayout
            p.add("0",sq0); 
            p.add("1",sq1); 
            p.add("2",sq2); 
            JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,tree,p); 
            sp.setEnabled(false); 
            tree.addTreeSelectionListener(this); 
            son.add(sp); 
            setVisible(true); 
            setResizable(false); 
        } 
      public void valueChange(TreeSelectionEvent e) 
      { 
      if(e.getSource()==tree) 
      { 
      DefaultMutableTreeNode 
      node=(DefaultMutableTreeNode)tree.getLastSelectPathComponent(); 
      String str=node.toString(); 
      if(str.equals("学生信息管理系统")) 
      car.show(p,"0"); 
      else if(str.equals("查询人员")) car.show(p,"1"); 
      else if(str.equals("添加信息")) car.show(p,"2"); 
      else if(str.equals("修改信息")) car.show(p,"1"); 
      else if(str.equals("删除信息")) car.show(p,"1"); 
          } 
        } 
      public static void main(String args[]) 
      { 
      st=new Stu(); 
        } 
          } 
    class Pane extends JPanel 

    JTextArea ta=new JTextArea("这是一个年级的学生管理系统!\n该年级共有9个班级\n每班学生不超过60个"); 
    public Pane() 

    setLayout(new BorderLayout()); 
    ta.setBackground(Color.orange); 
    ta.setEditable(false); 
    add(ta,"Center"); 
        } 
        } 
      

  3.   

    try{
        conn=DriverManger.getConnection("jdbc.odbc:stu","stu","");
        stmt=conn.createStatement();
        catch(SQLException ee){
        } 没有catch!
      

  4.   

    错误多如牛毛     这根本不是程序    只是一堆字母而已   
    如果是lz自己写的,  建议还是用Eclipse重写。
    如果不是lz自己写的,  不要在这个上面浪费时间了 。
      

  5.   

    楼主你应该把代码弄整齐点啊 ide有这个功能的
      

  6.   

    问题不少,以下是调试运行过的代码。package com.iSnail.util.ui;import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.Statement;import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.JTextArea;
    import javax.swing.JTree;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.DefaultMutableTreeNode;public class Treemenu extends JFrame implements TreeSelectionListener {
    static int N1 = 9;
    static int N2 = 60;
    static Treemenu st;
    JTree tree = null;
    static JPanel p = new JPanel();
    Pane sp0 = new Pane();
    Pane sp1 = new Pane();
    Pane sp2 = new Pane();
    Pane sp21 = new Pane();
    static CardLayout car = new CardLayout(); public Treemenu() {
    super("学生信息管理系统");
    Container con = getContentPane();
    setSize(700, 500);
    setLocation(100, 100); // 改为setLocation
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("学生信息管理系统"); // 改为
    // DefaultMutableTreeNode
    // node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
    DefaultMutableTreeNode t11 = new DefaultMutableTreeNode("查询人员");
    DefaultMutableTreeNode t12 = new DefaultMutableTreeNode("添加信息");
    DefaultMutableTreeNode t13 = new DefaultMutableTreeNode("修改信息");
    DefaultMutableTreeNode t14 = new DefaultMutableTreeNode("删除信息");
    root.add(t11);
    root.add(t12);
    root.add(t13);
    root.add(t14);
    tree = new JTree(root);
    p.setLayout(car); // setLayout
    p.add("0", sp0);
    p.add("1", sp1);
    p.add("2", sp2);
    JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, tree,
    p);
    sp.setEnabled(false);
    tree.addTreeSelectionListener(this);
    con.add(sp);
    setVisible(true);
    setResizable(false);
    }
    public static void main(String args[]) {
    st = new Treemenu();
    } public void valueChanged(TreeSelectionEvent e) {
    if (e.getSource() == tree) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
    .getLastSelectedPathComponent();
    String str = node.toString();
    if (str.equals("学生信息管理系统"))
    car.show(p, "0");
    else if (str.equals("查询人员"))
    car.show(p, "1");
    else if (str.equals("添加信息"))
    car.show(p, "2");
    else if (str.equals("修改信息"))
    car.show(p, "1");
    else if (str.equals("删除信息"))
    car.show(p, "1");
    }
    }
    }class Pane extends JPanel {
    JTextArea ta = new JTextArea("这是一个年级的学生管理系统!\n该年级共有9个班级\n每班学生不超过60个"); public Pane() {
    setLayout(new BorderLayout());
    ta.setBackground(Color.orange);
    ta.setEditable(false);
    add(ta, "Center");
    }
    }