发布网友 发布时间:2024-10-23 20:47
共1个回答
热心网友 时间:2024-11-06 20:58
class FrameTest extends JFrame{
JButton btnExit=new JButton("退出");
JButton btnNext=new JButton("下条信息");
JTextArea txtInfo=new JTextArea ();
JPanel p2=new JPanel(new GridBagLayout());
public FrameTest(){
init();
}
public FrameTest(String x){
super(x);
init();
}
public void init() {
setSize(500,540);
setResizable( false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp=getContentPane();
cp.setLayout(null);
txtInfo.setBorder(new TitledBorder("豆类油脂"));
JMenuBar jmb=new JMenuBar();
this.setJMenuBar(jmb);
txtInfo.setFont(new Font("楷体", Font.PLAIN, 14));
txtInfo.setCaretColor(Color.BLUE);
txtInfo.setLineWrap(true);
txtInfo.setText("1.周二,"
+ "芝加哥期货交易所(CBOT)大豆市场收盘上涨,延续近期涨幅,因为南美大豆产量下滑而中国的需求旺盛。");
txtInfo.setBounds(40, 50, 410, 200);
cp.add(txtInfo);
JPanel p1=new JPanel();
p1.setBounds(0, 0, 500, 50);
p1.setBackground(Color.cyan);
p1.setBorder(new TitledBorder("————————————————每日提示————————————————"));
cp.add(p1);
JPanel p3=new JPanel();
p3.setBounds(0, 450, 500, 50);
p3.setBackground(Color.cyan);
p3.setBorder(new TitledBorder("————————————————每日提示————————————————"));
cp.add(p3);
JPanel p4=new JPanel();
p4.setBounds(0, 50, 40, 400);
p4.setBackground(Color.cyan);
cp.add(p4);
JPanel p5=new JPanel();
p5.setBounds(450, 50, 50, 400);
p5.setBackground(Color.cyan);
cp.add(p5);
JPanel p2=new JPanel();
p2.setBounds(35, 250, 420, 200);
p2.setBackground(Color.pink);
p2.setBorder(new TitledBorder(""));
cp.add(p2);
Choice ch1=new Choice();
ch1.setPreferredSize(new Dimension(150, 20));
p1.setFont(new Font("楷体", Font.PLAIN, 25));
ch1.add("豆类油脂");
ch1.add("白糖");
ch1.add("食盐");
p1.add(ch1);
CheckboxGroup cp1=new CheckboxGroup();
p2.setFont(new Font("楷体", Font.PLAIN, 25));
Checkbox c1=new Checkbox("不再提示",true,cp1);
p2.add(c1);
Checkbox c2=new Checkbox("隔天提示",false,cp1);
p2.add(c2);
p2.add(btnNext) ;
p2.add(btnExit);
setVisible(true);
btnNext.addActionListener(listenerBtn);
btnExit.addActionListener(listenerBtn);
}
ActionListener listenerBtn =new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("mouseClicked");
if (e.getSource().equals(btnExit)){
System.exit(0);
}else if (e.getSource().equals(btnNext)){
txtInfo.setText("txtInfotxtInfotxtInfotxtInfotxtInfotxtInfotxtInfo");
}
}
};
public static void main(String[] args) {
new FrameTest("每日提醒");
}
}