JAVA图形界面问题
我写个简单的界面,加上图片后,文本框前面的两个标签显示不出来,谁能告诉我这是怎么回事?能帮我改下就更好了!(代码在下面)packagewindow;importjava....
我写个简单的界面,加上图片后,文本框前面的两个标签显示不出来,谁能告诉我这是怎么回事?能帮我改下就更好了!(代码在下面)
package window;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class window2 {
public static void main(String[] args) throws IOException {
JLabel j1=new JLabel("用户:");
JLabel j2=new JLabel("密码:");
bbk jp=new bbk(); //class bbk extends Panel
jp.setBackground(Color.yellow);
JFrame jf=new JFrame();
TextField t1=new TextField("你的名字",20);
TextField t2=new TextField("你的密码",20);
Button b=new Button("确认");
jp.add(j1);
jp.add(t1);
jp.add(j2);
jp.add(t2);
jp.add(b);
jf.add(jp);
jf.setSize(485, 616);
jf.setVisible(true);
}
}
// 绘制图片
class bbk extends Panel{
private BufferedImage bj;
public bbk(){
String Path="P1.png";//图片P1
try {
bj=ImageIO.read(getClass().getResource(Path));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("获取图片出错",e);
}
}
public void paint(Graphics g) {
g.drawImage(bj, 0, 0,null);
}
} 展开
package window;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class window2 {
public static void main(String[] args) throws IOException {
JLabel j1=new JLabel("用户:");
JLabel j2=new JLabel("密码:");
bbk jp=new bbk(); //class bbk extends Panel
jp.setBackground(Color.yellow);
JFrame jf=new JFrame();
TextField t1=new TextField("你的名字",20);
TextField t2=new TextField("你的密码",20);
Button b=new Button("确认");
jp.add(j1);
jp.add(t1);
jp.add(j2);
jp.add(t2);
jp.add(b);
jf.add(jp);
jf.setSize(485, 616);
jf.setVisible(true);
}
}
// 绘制图片
class bbk extends Panel{
private BufferedImage bj;
public bbk(){
String Path="P1.png";//图片P1
try {
bj=ImageIO.read(getClass().getResource(Path));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("获取图片出错",e);
}
}
public void paint(Graphics g) {
g.drawImage(bj, 0, 0,null);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询