import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
class MyFrame extends JFrame{
private JButton jButton1 = new JButton();
public void paint(Graphics g){
super.paint(g);
ImageIcon icon = new ImageIcon("E:/temp/aaa.jpeg");
g.drawImage(icon.getImage(),0,0,getWidth(),getHeight(),this);
}
public static void main(String[] args){
MyFrame f = new MyFrame();
f.setSize(200,200); f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {System.exit(0);}
}); f.show();
f.repaint();
} public MyFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(72, 49, 108, 31));
jButton1.setText("jButton1");
this.getContentPane().setLayout(null);
this.getContentPane().add(jButton1, null);
}
}
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
class MyFrame extends JFrame{
private JButton jButton1 = new JButton();
public void paint(Graphics g){
super.paint(g);
ImageIcon icon = new ImageIcon("E:/temp/aaa.jpeg");
g.drawImage(icon.getImage(),0,0,getWidth(),getHeight(),this);
}
public static void main(String[] args){
MyFrame f = new MyFrame();
f.setSize(200,200); f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {System.exit(0);}
}); f.show();
f.repaint();
} public MyFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(72, 49, 108, 31));
jButton1.setText("jButton1");
this.getContentPane().setLayout(null);
this.getContentPane().add(jButton1, null);
}
}
用JB的可视化就可以了
背景图之类的都有属性框可以选,按钮也只是拖进去就可以了
特别是用XY布局的更方便
to wanglh2000() 程序启动以后按钮没有显示出来,图片遮住了按钮...