在A中创建B的对象,调用B的重载构造器为B的属性赋值.

解决方案 »

  1.   

    class A
    {
       public static void main(String args[])
       {
          class ob = new B("aaa",10);
       }
    }
    class B 
    {
       String a="";
       int b = 0;
       public B()
       {
         System.out.println("构造器一");
       }
       public B(String a,int b)
       {
          this.a = a;
          this.b = b;
       }
    }
      

  2.   

    那么我在如果要加入Swing组件!应该放在哪个里面?public B()
    还是public B(String a,int b)?能再告诉我第二个问题吗??谢谢!先加你二十分
      

  3.   

    一下是我的代码!麻烦看看!
    package universityinformationmanagement;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import com.borland.dbswing.*;
    import com.borland.dx.sql.dataset.*;
    import com.borland.dx.dataset.*;/**
     * <p>Title: University Information Management System</p>
     * <p>Description: </p>
     * <p>Copyright: JasonLee  Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author JasonLee
     * @version 1.0
     */public class StuFrame extends JFrame {
      JPanel contentPane;
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      JPanel jPanel3 = new JPanel();
      JButton jButton2 = new JButton();
      JButton jButton4 = new JButton();
      JButton jButton5 = new JButton();
      JLabel jLabel1 = new JLabel();
      XYLayout xYLayout1 = new XYLayout();
      BorderLayout borderLayout1 = new BorderLayout();
      JLabel jLabel3 = new JLabel();
      JLabel jLabel4 = new JLabel();
      JLabel jLabel5 = new JLabel();
      JLabel jLabel6 = new JLabel();
      JLabel jLabel7 = new JLabel();
      JdbTextField StuID = new JdbTextField();
      JdbTextField Stu_name = new JdbTextField();
      JdbTextField Brithday = new JdbTextField();
      JdbTextField Age = new JdbTextField();
      JdbTextField Pass = new JdbTextField();
      JLabel jLabel8 = new JLabel();
      JTextField PassR = new JTextField();
      Database UIMSDB = new Database();
      JdbLabel Imagelabel = new JdbLabel();
      JComboBox GenderCB = new JComboBox();
      QueryDataSet StuDataSet = new QueryDataSet();
      Column BirthdayCol = new Column();
      ParameterRow parameterRow1 = new ParameterRow();
      Column name = new Column();
      //Construct the frame
      public StuFrame(String para) {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit(para);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit(String para) throws Exception  {    //try{name=para;}
        //catch(Exception ex){ex.printStackTrace();}    contentPane = (JPanel) this.getContentPane();
        contentPane.setDebugGraphicsOptions(0);
        contentPane.setDoubleBuffered(true);
        this.setSize(new Dimension(500,450));
        this.setTitle("Student Information");
        jButton2.setText("jButton2");
        jButton4.setText("jButton4");
        jButton5.setText("jButton5");
        jLabel1.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel1.setText("Student ID:");
        jPanel1.setLayout(xYLayout1);
        jPanel1.setDebugGraphicsOptions(0);
        jPanel2.setLayout(borderLayout1);
        jLabel3.setText("Name:");
        jLabel3.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel4.setText("Gender:");
        jLabel4.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel5.setText("Birthday");
        jLabel5.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel6.setText("Age:");
        jLabel6.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel7.setText("Password");
        jLabel7.setFont(new java.awt.Font("Serif", 1, 14));
        StuID.setEditable(false);
        StuID.setColumnName("Stu_ID");
        StuID.setDataSet(StuDataSet);
        Stu_name.setColumnName("Stu_name");
        Stu_name.setDataSet(StuDataSet);
        Brithday.setDebugGraphicsOptions(0);
        Brithday.setColumns(0);
        Brithday.setColumnName("Birthday");
        Brithday.setDataSet(StuDataSet);
        Age.setDoubleBuffered(false);
        Age.setEditable(false);
        Age.setColumnName("Age");
        Age.setDataSet(StuDataSet);
        Pass.setColumnName("Password");
        Pass.setDataSet(StuDataSet);
        jLabel8.setFont(new java.awt.Font("Serif", 1, 14));
        jLabel8.setText("Repeat Password");
        PassR.setPreferredSize(new Dimension(80, 22));
        PassR.setText("");
        UIMSDB.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:UIMS", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
        Imagelabel.setPreferredSize(new Dimension(140, 380));
        Imagelabel.setText("jdbLabel1");
        Imagelabel.setColumnName("Image");
        Imagelabel.setDataSet(StuDataSet);
        GenderCB.setEnabled(true);
        GenderCB.setPreferredSize(new Dimension(80, 22));
        BirthdayCol.setColumnName("Birthday");
        BirthdayCol.setDataType(com.borland.dx.dataset.Variant.DATE);
        BirthdayCol.setTableName("student");
        BirthdayCol.setServerColumnName("Birthday");
        BirthdayCol.setSqlType(93);
        StuDataSet.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(UIMSDB, "select * from student where Stu_name = :name", parameterRow1, true, Load.AS_NEEDED));
        name.setColumnName("name");
        name.setDataType(com.borland.dx.dataset.Variant.STRING);
        name.setPreferredOrdinal(0);
        name.setServerColumnName("name");
        name.setSqlType(0);
        contentPane.add(jPanel1,  BorderLayout.CENTER);
        jPanel1.add(jLabel1,     new XYConstraints(70, 77, -1, -1));
        jPanel1.add(jLabel3,     new XYConstraints(70, 117, -1, -1));
        jPanel1.add(jLabel4,    new XYConstraints(70, 157, -1, -1));
        jPanel1.add(jLabel5,   new XYConstraints(70, 197, -1, -1));
        jPanel1.add(jLabel6,    new XYConstraints(70, 237, -1, -1));
        jPanel1.add(jLabel7,      new XYConstraints(70, 277, -1, -1));
        jPanel1.add(StuID,       new XYConstraints(210, 77, 71, -1));
        jPanel1.add(Stu_name,       new XYConstraints(210, 117, 71, -1));
        jPanel1.add(Age,       new XYConstraints(210, 237, 71, -1));    jPanel1.add(Brithday,   new XYConstraints(210, 197, -1, -1));
        jPanel1.add(Pass,    new XYConstraints(210, 277, 84, -1));
        jPanel1.add(jLabel8,    new XYConstraints(70, 317, -1, -1));
        jPanel1.add(PassR,      new XYConstraints(210, 317, 85, -1));
        jPanel1.add(GenderCB,    new XYConstraints(210, 157, 72, -1));
        contentPane.add(jPanel2,  BorderLayout.EAST);
        jPanel2.add(Imagelabel, BorderLayout.NORTH);
        contentPane.add(jPanel3,  BorderLayout.SOUTH);
        jPanel3.add(jButton5, null);
        jPanel3.add(jButton4, null);
        jPanel3.add(jButton2, null);
        Imagelabel.setColumnNameIcon("Image");
        StuDataSet.setColumns(new Column[] {BirthdayCol});
        parameterRow1.setColumns(new Column[] {name});
        GenderCB.addItem("Male");
        GenderCB.addItem("Female");
        if (StuDataSet.getString("Gender").equals("Male")){
          GenderCB.setSelectedIndex(0);
        }else{ GenderCB.setSelectedIndex(1);}  }
      //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);
        }
      }
    }
    这样我所有的组件都不见了!能告诉我这是什么回事吗?
      

  4.   

    你的main函数都没有,怎么显示,不明你说组件看不见什么意思