用java创建一个带按钮对象的窗口的程序,帮我看看哪里错了?

来源:百度知道 编辑:UC知道 时间:2024/06/10 02:11:27
我编写的程序如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JB extends JFrame
{
private JButton button1,button2;
public JB(JFrame f,JPanel p){
f.add(p);
button1=new JButton("按钮1");
button1.setFont(new Font("Serif",Font.PLAIN,20));

ImageIcon img1=new ImageIcon("图片/1.gif");/*此处的图片都事先放在同一文件夹下了*/
ImageIcon img2=new ImageIcon("图片/2.gif");
button2=new JButton("按钮2",img2);
button2.setRolloverIcon(img1);
button2.setFont(new Font("Serif",Font.PLAIN,14));

BHandler h=new BHandler();
button1.addActionListener(h);
button2.addActionListener(h);

p.add(button1);
p.add(button2);

}
public static void main(String [] args){
JB f1=new JB(new JF0("添加按钮的窗口"),new JPanel());
}

protect class JF0 extends JFrame{
Container c;
p

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JB extends JFrame {

public JB() {
super("图形用户界面"); // 调用父类JFrame的构造方法,给窗口命名
setBounds(200, 200, 500, 400);// 设置窗口位置、窗口大小

/*
* try{//设置外观
* UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
* }catch(Exception e){}
*/
Container c = getContentPane();
c.add(new MyPanel()); //添加Panel
c.setBackground(Color.yellow);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true); // 设置窗口是否为可见
}

private class MyPanel extends JPanel {
private JButton button1, button2;
public MyPanel() {
button1 = new JButton("按钮1");
button1.setFont(new Font("Serif", Font.PLAIN, 20));

ImageIcon img1 = new ImageIcon("图片/1.gif");/* 此处的图片都事先放在同一文件夹下了 */
ImageIcon img2 =