当前位置: 技术问答>java相关
帮忙看一下小代码
来源: 互联网 发布时间:2015-08-12
本文导语: 代码如下: public class op { public static void main(String ars[]) { win obj=new win(); } } class win { one oneobj; two twoobj; JFrame fra; JPanel pan; JButton but1; JButton but2; public win...
代码如下:
public class op
{
public static void main(String ars[])
{
win obj=new win();
}
}
class win
{
one oneobj;
two twoobj;
JFrame fra;
JPanel pan;
JButton but1;
JButton but2;
public win()
{
oneobj=new one();
twoobj=new two();
oneButton onechick=new oneButton();
twoButton twochick=new twoButton();
fra=new JFrame();
pan=new JPanel();
but1=new JButton("one");
but2=new JButton("two");
but1.addActionListener(onechick);
but2.addActionListener(twochick);
pan.add(but1);
pan.add(but2);
fra.getContentPane().add(pan);
fra.setSize(100,100);
fra.show();
}
class oneButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
oneobj.fra.show();
}
}
class twoButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
twoobj.fra.show();
}
}
}
class one
{
JFrame fra;
JPanel pan;
JLabel lab;
JTextField text;
public one()
{
fra=new JFrame();
pan=new JPanel();
lab=new JLabel("ad");
text=new JTextField(6);
pan.add(lab);
pan.add(text);
fra.getContentPane().add(pan);
fra.setSize(100,100);
}
}
class two extends one
{
JLabel lab;
public two()
{
lab=new JLabel("fg");
}
}
因为界面一样,lab不一样,用继承,但显示的确是one,帮忙改一下。
public class op
{
public static void main(String ars[])
{
win obj=new win();
}
}
class win
{
one oneobj;
two twoobj;
JFrame fra;
JPanel pan;
JButton but1;
JButton but2;
public win()
{
oneobj=new one();
twoobj=new two();
oneButton onechick=new oneButton();
twoButton twochick=new twoButton();
fra=new JFrame();
pan=new JPanel();
but1=new JButton("one");
but2=new JButton("two");
but1.addActionListener(onechick);
but2.addActionListener(twochick);
pan.add(but1);
pan.add(but2);
fra.getContentPane().add(pan);
fra.setSize(100,100);
fra.show();
}
class oneButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
oneobj.fra.show();
}
}
class twoButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
twoobj.fra.show();
}
}
}
class one
{
JFrame fra;
JPanel pan;
JLabel lab;
JTextField text;
public one()
{
fra=new JFrame();
pan=new JPanel();
lab=new JLabel("ad");
text=new JTextField(6);
pan.add(lab);
pan.add(text);
fra.getContentPane().add(pan);
fra.setSize(100,100);
}
}
class two extends one
{
JLabel lab;
public two()
{
lab=new JLabel("fg");
}
}
因为界面一样,lab不一样,用继承,但显示的确是one,帮忙改一下。
|
//lab=new JLabel("fg");
lab.setText("fg");
--- ZJQ
lab.setText("fg");
--- ZJQ