能告诉我这怎样实现吗?? 在A中创建B的对象,调用B的重载构造器为B的属性赋值. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; }} 那么我在如果要加入Swing组件!应该放在哪个里面?public B()还是public B(String a,int b)?能再告诉我第二个问题吗??谢谢!先加你二十分 一下是我的代码!麻烦看看!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); } }}这样我所有的组件都不见了!能告诉我这是什么回事吗? 你的main函数都没有,怎么显示,不明你说组件看不见什么意思 关于类的实例化和指针的一个问题 java 二级 谁来帮我讲解一下这道题~~~谢谢 eclipse,急 怎样在JTable里设定单元格的cellrender 发现一个群,里面极多高手,群号:9128047,赶快进啊 动态编程问题!高手请进! 我刚开始学习JAVA,请教几本JAVA的好书,及网站!!!!!!!!! sos! 大家帮忙! java对数据库的开发 如何用java 编写可以对任何形式的文件加密(或加锁)的程序????? JTextfield 的输入限制问题
{
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;
}
}
还是public B(String a,int b)?能再告诉我第二个问题吗??谢谢!先加你二十分
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);
}
}
}
这样我所有的组件都不见了!能告诉我这是什么回事吗?