编写一个小应用程序,采用BorderLayout布局,北面添加一个Choice组件,该组件有四个课程名称的选项。中心添加一个文本区,当选择Choice组件中的某个选项后,文本区显示对课程的介绍
public class Frame1 extends JFrame
{
XYLayout xYLayout1 = new XYLayout();
Choice choice1 = new Choice();
TextArea textArea1 = new TextArea();
public Frame1()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setBackground(Color.lightGray);
this.getContentPane().setLayout(xYLayout1);
xYLayout1.setHeight(278);
xYLayout1.setWidth(425);
this.getContentPane().add(choice1, new XYConstraints(91, 3, 132, 19));
choice1.add("语文");
choice1.add("数学");
choice1.add("英语");
choice1.add("JAVA程序设计");
this.getContentPane().add(textArea1,new XYConstraints(17, 37, 372, 227));
}
public void itemStateChanged(ItemEvent e)
{ String c = choice1.getSelectedItem();
if(c=="语文")
{
textArea1.setText("语文");
}
if(c=="数学")
{
textArea1.setText("数学");
}
if(c=="英语")
{
textArea1.setText("英语");
}
if(c=="JAVA程序设计")
{
textArea1.setText("JAVA程序设计");
} }
public static void main(String[] args)
{
Frame1 f = new Frame1();
f.setSize(400,300);
f.setVisible(true);}
}
鼠标事件要怎么写,请教高手
public class Frame1 extends JFrame
{
XYLayout xYLayout1 = new XYLayout();
Choice choice1 = new Choice();
TextArea textArea1 = new TextArea();
public Frame1()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setBackground(Color.lightGray);
this.getContentPane().setLayout(xYLayout1);
xYLayout1.setHeight(278);
xYLayout1.setWidth(425);
this.getContentPane().add(choice1, new XYConstraints(91, 3, 132, 19));
choice1.add("语文");
choice1.add("数学");
choice1.add("英语");
choice1.add("JAVA程序设计");
this.getContentPane().add(textArea1,new XYConstraints(17, 37, 372, 227));
}
public void itemStateChanged(ItemEvent e)
{ String c = choice1.getSelectedItem();
if(c=="语文")
{
textArea1.setText("语文");
}
if(c=="数学")
{
textArea1.setText("数学");
}
if(c=="英语")
{
textArea1.setText("英语");
}
if(c=="JAVA程序设计")
{
textArea1.setText("JAVA程序设计");
} }
public static void main(String[] args)
{
Frame1 f = new Frame1();
f.setSize(400,300);
f.setVisible(true);}
}
鼠标事件要怎么写,请教高手
{
XYLayout xYLayout1 = new XYLayout();
Choice choice1 = new Choice();
TextArea textArea1 = new TextArea();
---------------------------
建议你还是先打好基础吧.
AWT和SWing组件不要混用,否则会出现层次错位==的问题.再有你在哪用的"BorderLayout"? 难道XYLayout extends BorderLayout?if(c=="JAVA程序设计"),请这样写 if("JAVA程序设计".equals(c))