当前位置:编程学习 > JAVA >>

标题不显示

不知道为什么 我的组件在窗体不显示
import javax.swing.JFrame;
 import javax.swing.JLabel;
 import java.io.File;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import javax.imageio.ImageIO;
 import java.awt.Graphics;
 import java.awt.Font;
 import java.awt.Color;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import javax.swing.JOptionPane;
import java.awt.Container;
 
 
 
  public class Fivechess extends JFrame implements MouseListener{
   JLabel l1;
   JLabel l2;
   JLabel l3;
   JLabel l4;
  // Container cp;
  BufferedImage image=null;
  int x=0;
  int y=0;
  int allChess[][]=new int[19][19];
  boolean isBlack=true;
  boolean isWin=true;
  boolean canPlay=true;
  String message="黑方先行";
  public Fivechess(){
  this.setTitle("五子棋");
  this.setSize(500,600);
  this.setLocation(200,200);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
  this.addMouseListener(this);
  try{
      this.image=ImageIO.read(new File("E:/src/五子棋/mini.jpg"));
    
      }
      catch(IOException e){
       e.printStackTrace();
      }
  l1=new JLabel("游戏开始");
  this.getContentPane().add(l1);
  l1.setBounds(410,85,30,40);
  l2=new JLabel("游戏设置");
  l2.setBounds(410,115,30,40);
  this.getContentPane().add(l2);
  l3=new JLabel("退出");
  l3.setBounds(410,145,30,40);
  this.getContentPane().add(l3);
  l4=new JLabel("关于");
  l4.setBounds(410,175,30,40);
  this.getContentPane().add(l4);
  this.setVisible(true);
  }
我是初学者 --------------------编程问答-------------------- 你的组件就没容器装。 --------------------编程问答-------------------- 我还是不太懂  我又改了一下
 public class Fivechess extends JFrame implements MouseListener{
   JButton l1;
    JButton l2;
   JButton l3;
    JButton l4;
 //  Container cp;
  BufferedImage image=null;
  int x=0;
  int y=0;
  int allChess[][]=new int[19][19];
  boolean isBlack=true;
  boolean isWin=true;
  boolean canPlay=true;
  String message="黑方先行";
  public Fivechess(){
//  p1=new JPanel();
//      cp=getContentPane();
  this.setTitle("五子棋");
  this.setSize(500,600);
  this.setLocation(200,200);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
  this.addMouseListener(this);
try{
      this.image=ImageIO.read(new File("E:/src/五子棋/mini.jpg"));
    
      }
      catch(IOException e){
       e.printStackTrace();
      }
//       p1.setLayout(new BorderLayout());
  l1=new  JButton("游戏开始");
  this.add(l1);
  l1.setBounds(410,50,80,90);
  this.add(p1);
  l2=new  JButton("游戏设置");
  l2.setBounds(410,130,80,90);
  this.add(l2);
  l3=new  JButton("退出");
  l3.setBounds(410,210,80,90);
  this.add(l3);
  l4=new  JButton("关于");
  l4.setBounds(410,290,80,90);
  this.add(l4);
 
  this.setVisible(true);
  }
JFrame是一个容器吧,用this加在frame上,可是我的setbounds好像不起作用
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,