问题同上,代码如下:只是很奇怪!!!谢谢...
import java.awt.Panel;
import java.awt.Button;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Choice;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionListener;public class AdvanceSetFrame extends Frame implements ActionListener,
ItemListener {
private Choice timeChoice;
private Button btnEnter, btnCancel;
private Panel panel;
final String enterStr = "确定";
final String cancelStr = "取消";
final static String title = "高级设置";// 当static不标时会有提示于super(title):Cannot // refer to an instance field title
// while explicitly invoking a
// constructor
public AdvanceSetFrame() {
super(title);
setBounds(500, 300, 400, 200);
setLayout(null);
panel = new Panel();
timeChoice = new Choice();
timeChoice.add("1.0");
timeChoice.add("1.5");
timeChoice.add("2.0");
timeChoice.add("2.5");
timeChoice.add("3.0");
timeChoice.setVisible(true);
timeChoice.addItemListener(this);
panel.add(timeChoice);
add(panel);
setVisible(true);
btnEnter = new Button(enterStr);
btnCancel = new Button(cancelStr);
btnEnter.addActionListener(this);
btnCancel.addActionListener(this);
btnEnter.setBounds(145, 170, 50, 20);
btnCancel.setBounds(205, 170, 50, 20);
add(btnEnter);
add(btnCancel);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
}
});
} public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if (e.getItemSelectable() == timeChoice) {
// if (timeChoice.getSelectedIndex() == 0) {
// } else if (timeChoice.getSelectedIndex() == 1) {
// } else if (timeChoice.getSelectedIndex() == 2) {
// } else if (timeChoice.getSelectedIndex() == 3) {
// } else if (timeChoice.getSelectedIndex() == 4) {
// }
}
} @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == btnEnter){
this.setVisible(false);
}else if(e.getSource() == btnCancel){
this.setVisible(false);
}
}
}
public class BeadrollFrame{ public static void main(String []args){
new AdvanceSetFrame();
}
}

解决方案 »

  1.   

    panel要加位置
    panel.setBounds(new Rectangle());
      

  2.   

    加上了的话,效果还是一样没有显示Choice,郁闷.....
      

  3.   

    建议你在一个JPanel上做这些布局操作,JFrame的布局不要变。
    用空布局的话,最好在纸上定义好坐标。
      

  4.   

    其实我刚接触awt,只是想把java.awt.*中的基本功能明白清楚,
    轻量级的javax.swing.*;我还不会呢!!!!题目中是指如何在java.awt.*;中的类实现.拒绝javax.swing.*;
    谢谢大家的回复.
      

  5.   

    setLayout(null)话,你要指定坐标值