java GUI 窗口中的容器不能显示
publicclassFrameTestextendsJFrame{publicFrameTest(){//Imageimage=this.getToolkit().ge...
public class FrameTest extends JFrame{
public FrameTest(){
//Image image=this.getToolkit().getImage("d:/image/loading.gif");
//this.setIconImage(image);
this.setTitle("关闭窗体");
this.addWindowListener(
new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(100, 100, 600, 600);
this.setVisible(true);
}
public static void main(String args[]){
FrameTest frameTest=new FrameTest();
JPanel jPanel=new JPanel();
JLabel jLabel=new JLabel();
jPanel.add(jLabel);
frameTest.add(jPanel);
frameTest.repaint();
}
}
有能力的话,随便帮我解决一下更换图标的问题,也是不是显示。 展开
public FrameTest(){
//Image image=this.getToolkit().getImage("d:/image/loading.gif");
//this.setIconImage(image);
this.setTitle("关闭窗体");
this.addWindowListener(
new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(100, 100, 600, 600);
this.setVisible(true);
}
public static void main(String args[]){
FrameTest frameTest=new FrameTest();
JPanel jPanel=new JPanel();
JLabel jLabel=new JLabel();
jPanel.add(jLabel);
frameTest.add(jPanel);
frameTest.repaint();
}
}
有能力的话,随便帮我解决一下更换图标的问题,也是不是显示。 展开
2个回答
展开全部
把loading.gif拷贝到源代码所在目录
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class FrameTest extends JFrame{
public FrameTest(){
ImageIcon ii = new ImageIcon(this.getClass().getResource("loading.gif"));
setIconImage(ii.getImage());
this.setTitle("关闭窗体");
this.addWindowListener(
new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(100, 100, 600, 600);
this.setVisible(true);
}
public static void main(String args[]){
FrameTest frameTest=new FrameTest();
JPanel jPanel=new JPanel();
JLabel jLabel=new JLabel();
jLabel.setText("haha");
jPanel.add(jLabel);
frameTest.add(jPanel);
frameTest.repaint();
frameTest.setVisible(true);
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class FrameTest extends JFrame{
public FrameTest(){
ImageIcon ii = new ImageIcon(this.getClass().getResource("loading.gif"));
setIconImage(ii.getImage());
this.setTitle("关闭窗体");
this.addWindowListener(
new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(100, 100, 600, 600);
this.setVisible(true);
}
public static void main(String args[]){
FrameTest frameTest=new FrameTest();
JPanel jPanel=new JPanel();
JLabel jLabel=new JLabel();
jLabel.setText("haha");
jPanel.add(jLabel);
frameTest.add(jPanel);
frameTest.repaint();
frameTest.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询