package myproject;import java.awt.Button;
import java.awt.Panel;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextArea;
import javax.swing.ImageIcon;import javax.swing.ImageIcon;public class TextComents extends Frame {
TextArea txtComment = new TextArea();
Label labelComment = new Label("请输入姓名");
Button buttonComment = new Button("开始查询");
Button ebuttonComment = new Button("退出");
Panel p1; ImageIcon image = new ImageIcon("myproject\\11.gif");
ImageIcon img = p1.
Button days[] = new Button[49];
Choice Month = new Choice();
Choice Year = new Choice();
Label lmonth = new Label("MONTH");
Label lyear = new Label("Year");
Label ltext = new Label("YEAR UPTO:::");
Panel p1, p2;
TextField textfield = new TextField(2); public TextComents(String title) {
super(title);
setLayout(new FlowLayout());
add(labelComment);
add(txtComment);
add(buttonComment);
add(ebuttonComment);
add(p1);
buttonComment.setSize(20, 30);
buttonComment.setBackground(new Color(202, 224, 95));
ebuttonComment.setSize(20, 30);
ebuttonComment.setBackground(new Color(202, 224, 95));
txtComment.setBackground(new Color(222, 241, 250));
txtComment.setSize(200, 300);
} public static void main(String args[]) {
TextComents t = new TextComents("绩效管理1.0");
t.setSize(500, 700);
t.setBackground(new Color(195, 218, 250));
t.setVisible(true); }
}
import java.awt.Panel;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextArea;
import javax.swing.ImageIcon;import javax.swing.ImageIcon;public class TextComents extends Frame {
TextArea txtComment = new TextArea();
Label labelComment = new Label("请输入姓名");
Button buttonComment = new Button("开始查询");
Button ebuttonComment = new Button("退出");
Panel p1; ImageIcon image = new ImageIcon("myproject\\11.gif");
ImageIcon img = p1.
Button days[] = new Button[49];
Choice Month = new Choice();
Choice Year = new Choice();
Label lmonth = new Label("MONTH");
Label lyear = new Label("Year");
Label ltext = new Label("YEAR UPTO:::");
Panel p1, p2;
TextField textfield = new TextField(2); public TextComents(String title) {
super(title);
setLayout(new FlowLayout());
add(labelComment);
add(txtComment);
add(buttonComment);
add(ebuttonComment);
add(p1);
buttonComment.setSize(20, 30);
buttonComment.setBackground(new Color(202, 224, 95));
ebuttonComment.setSize(20, 30);
ebuttonComment.setBackground(new Color(202, 224, 95));
txtComment.setBackground(new Color(222, 241, 250));
txtComment.setSize(200, 300);
} public static void main(String args[]) {
TextComents t = new TextComents("绩效管理1.0");
t.setSize(500, 700);
t.setBackground(new Color(195, 218, 250));
t.setVisible(true); }
}
ImageIcon img = p1. //没明白什么意思 Panel p1, p2; //p1重复定义add(p1); //运行时这句也报错如果都注释掉,程序可以运行,但相应的按钮都没有添加事件监听!没太理解LZ的意思是什么,想把程序改成什么样子?
import javax.swing.ImageIcon;
import javax.swing.JLabel;import javax.swing.ImageIcon;public class TextComents extends Frame { TextArea txtComment = new TextArea();
Label labelComment = new Label("请输入姓名");
Button buttonComment = new Button("开始查询");
Button ebuttonComment = new Button("退出");
//Panel p = new Panel(); ImageIcon image = new ImageIcon("e:\\pictures\\1.jpg");
JLabel label1=new JLabel(image);
//Image i=image.getImage();
Button days[] = new Button[49];
Choice Month = new Choice();
Choice Year = new Choice();
Label lmonth = new Label("MONTH");
Label lyear = new Label("Year");
Label ltext = new Label("YEAR UPTO:::");
//Panel p1, p2;
TextField textfield = new TextField(2); public TextComents(String title) {
super(title);
setLayout(new FlowLayout());
add(label1,BorderLayout.CENTER);
add(labelComment);
add(txtComment);
add(buttonComment);
add(ebuttonComment);
//add(p);
buttonComment.setSize(20, 30);
buttonComment.setBackground(new Color(202, 224, 95));
ebuttonComment.setSize(20, 30);
ebuttonComment.setBackground(new Color(202, 224, 95));
txtComment.setBackground(new Color(222, 241, 250));
txtComment.setSize(200, 300);
} public static void main(String args[]) {
TextComents t = new TextComents("绩效管理 1.0");
t.setSize(500, 700);
t.setBackground(new Color(195, 218, 250));
t.setVisible(true); }
}
给什么做背景,按钮?面板?
按钮:简单设置一下相应鼠标事件发生时的图片就行
面板:要在PAINTCOMPONENT里绘制背景的。
import java.awt.Choice;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;public class Test extends Frame implements ImageObserver {
TextArea txtComment = new TextArea(); Label labelComment = new Label("请输入姓名"); Button buttonComment = new Button("开始查询"); Button ebuttonComment = new Button("退出"); //Panel p1; Image image = Toolkit.getDefaultToolkit().createImage("wyl.jpg"); //ImageIcon img = p1; Button days[] = new Button[49]; Choice Month = new Choice(); Choice Year = new Choice(); Label lmonth = new Label("MONTH"); Label lyear = new Label("Year"); Label ltext = new Label("YEAR UPTO:::"); Panel p1, p2; TextField textfield = new TextField(2); public Test(String title) {
super(title);
p1 = new Panel();
setLayout(new FlowLayout());
add(labelComment);
add(txtComment);
add(buttonComment);
add(ebuttonComment);
add(p1);
buttonComment.setSize(20, 30);
buttonComment.setBackground(new Color(202, 224, 95));
ebuttonComment.setSize(20, 30);
ebuttonComment.setBackground(new Color(202, 224, 95));
txtComment.setBackground(new Color(222, 241, 250));
txtComment.setSize(200, 300);
}
public void paint(Graphics g) {
Insets insets = getInsets();
g.setColor(Color.white);
g.fillRect(0, 0, insets.left + getWidth(), insets.top + getHeight()); System.out.println("draw111");
if (image != null) {
g.drawImage(image, insets.top, insets.left, this);
System.out.println("draw");
}
}
public static void main(String args[]) {
Test t = new Test("绩效管理1.0");
t.setSize(500, 700);
t.setBackground(new Color(195, 218, 250));
t.setVisible(true); }
}
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class xinyu extends JFrame
{
ImageIcon img;
public xinyu()
{
img = new ImageIcon("1.jpg"); //你要添加的背景图片
JPanel panel = new JPanel() //重写了JPANEL的构造方法
{
public void paintComponent(Graphics g)
{
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
JButton button=new JButton("hello");
panel.add(button);
panel.setOpaque(false); //设置JPANEL为透明
setContentPane(panel);
}
public static void main(String[] args) {
xinyu t= new xinyu();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setSize(150, 150);
t.setVisible(true); }
}百度出来的例子,我这里可以看到