JPANEL 类 , 重写
paintCompontent 类,在
paintCompontent()方法中添加图片
class Welcome extends JPanel{
private static final long serialVersionUID = 1L;
intwidth=0, height=0;
Welcome(int x, int y, int width, int height){
this.width= width;
this.height = height;
this.setBounds(x, y, width, height);
}
@Override
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D) g;
ImageIcon icon = null;
try{
icon = new ImageIcon("filepath\\filename");
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g2d.drawImage(icon.getImage(), 0, 0,this.getSize().width,this.getSize().height, this);
g2d.setColor(new Color(150, 150, 180));
g2d.drawRect(0, 0, width-1, height-1);
g2d.setColor(Color.RED);
g2d.setFont(g.getFont().deriveFont(Font.BOLD|Font.ITALIC,28f));
g2d.drawString("演示", 230, 60);
g2d.setFont(g.getFont().deriveFont(Font.BOLD|Font.ITALIC,22f));
g2d.drawString("WINLAB", 600, 90);
//改变颜色和字体
g2d.setColor(Color.BLUE);
g2d.drawLine(590, 92, 690, 92);
}
}