package ght.play.paopaodragon.ui;import ght.play.paopaodragon.core.GameContext;
import ght.play.paopaodragon.module.Module;
import ght.play.paopaodragon.util.GlobalVariable;
import ght.play.paopaodragon.util.Position;import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Vector;import javax.swing.JFrame;
import javax.swing.JPanel;
public class GameScreen extends JFrame{
/**
* 为了去掉警告
*/
private static final long serialVersionUID = 1L;
/*
* 游戏的屏幕的宽
*/
public final int WIDTH=300;
/*
* 游戏的屏幕的长
*/
public final int HEIGHT=400;
private final int RESOLUTION=30;
//private GameEngine ge=new GameEngine(0);
public GameScreen(String name){
super(name);
setVisible(true);
setSize(WIDTH,HEIGHT);
getContentPane().add(new GamePanel(),BorderLayout.CENTER);
//setBackground(Color.WHITE);
//setLayout(new BorderLayout());
//setVisible(true);
GlobalVariable.newInstance().
put("CENTER",new Position(150,380));
}
private class GamePanel extends JPanel{
private static final long serialVersionUID = -316237384326279994L;
public void paintComponent(Graphics g) {
super.paintComponent(g);
GlobalVariable.newInstance().put("P",(Graphics2D)g);
//g.fillOval(0,0,100,100);
Vector<Module> allModules=GameContext.i().getModuleContainer().getModules();
for(Module module:allModules){
module.draw();
}
//File file=new File(getClass().getResource("")+"a/ball_black.png");
//ge.renderScreen();
//g.drawImage(new ImageIcon(getClass().getResource("")+"a/ball_black.png").getImage(),40,40,this);
//g.setColor(Color.black);
//g.fillOval((int)(Math.random()*300),0, 50,50);
}
}
public void start(){
final GameScreen paopao=this;
//paopao.setLayout(new BorderLayout());
//final Integer index=new Integer(1);
//paopao.pack();
//final GameEngine ge=new GameEngine(0);
//ge.run();
// paopao.getContentPane().add(new JPanel(){
// /**
// * 为了删掉警告
// */
// private static final long serialVersionUID = -5283610764609078407L;
//
// public void paintComponent(Graphics g) {
//
// super.paintComponent(g);
// GlobalVariable.newInstance().put("P",(Graphics2D)g);
//
// //g.fillOval(0,0,100,100);
//
// Vector<Module> allModules=GameContext.i().getModuleContainer().getModules();
//
//
// for(Module module:allModules){
// module.draw();
// }
//
// //File file=new File(getClass().getResource("")+"a/ball_black.png");
// //ge.renderScreen();
// //g.drawImage(new ImageIcon(getClass().getResource("")+"a/ball_black.png").getImage(),40,40,this);
// //g.setColor(Color.black);
// //g.fillOval((int)(Math.random()*300),0, 50,50);
// }
//
// public void paint(Graphics g){
// g.fillOval(0,0,100,100);
// }
//
//
// },BorderLayout.CENTER);
//GameEngine ge=new GameEngine(0);
//ge.run();
//paopao.setVisible(true);
//ge.register(paopao);
//this.getComponents();
//final GamePanel panel=(GamePanel)getContentPane().getComponent(0);
//panel.repaint();
// final GameScreen s=this;
//panel.paintComponent(panel.getGraphics());
new Thread(new Runnable(){
public void run(){
while(true){
try {
//Thread.sleep(RESOLUTION);
//paopao.paintComponents(paopao.getGraphics());
//paopao.paintComponents(paopao.getGraphics());
while(true){
Thread.sleep(RESOLUTION);
//panel.paintComponent(panel.getGraphics());
update(getGraphics());
}
} catch (Exception e) {
}
}
}
}).start();
}
public static void main(String[] args){
//GameScreen.start();
}
}程序刚启动的时候图形显示不出来,但只要一调整下窗口的大小,或者最大化,图形就可以显示了。不知道什么问题呀,郁闷死了。请大家赐教.....
import ght.play.paopaodragon.module.Module;
import ght.play.paopaodragon.util.GlobalVariable;
import ght.play.paopaodragon.util.Position;import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Vector;import javax.swing.JFrame;
import javax.swing.JPanel;
public class GameScreen extends JFrame{
/**
* 为了去掉警告
*/
private static final long serialVersionUID = 1L;
/*
* 游戏的屏幕的宽
*/
public final int WIDTH=300;
/*
* 游戏的屏幕的长
*/
public final int HEIGHT=400;
private final int RESOLUTION=30;
//private GameEngine ge=new GameEngine(0);
public GameScreen(String name){
super(name);
setVisible(true);
setSize(WIDTH,HEIGHT);
getContentPane().add(new GamePanel(),BorderLayout.CENTER);
//setBackground(Color.WHITE);
//setLayout(new BorderLayout());
//setVisible(true);
GlobalVariable.newInstance().
put("CENTER",new Position(150,380));
}
private class GamePanel extends JPanel{
private static final long serialVersionUID = -316237384326279994L;
public void paintComponent(Graphics g) {
super.paintComponent(g);
GlobalVariable.newInstance().put("P",(Graphics2D)g);
//g.fillOval(0,0,100,100);
Vector<Module> allModules=GameContext.i().getModuleContainer().getModules();
for(Module module:allModules){
module.draw();
}
//File file=new File(getClass().getResource("")+"a/ball_black.png");
//ge.renderScreen();
//g.drawImage(new ImageIcon(getClass().getResource("")+"a/ball_black.png").getImage(),40,40,this);
//g.setColor(Color.black);
//g.fillOval((int)(Math.random()*300),0, 50,50);
}
}
public void start(){
final GameScreen paopao=this;
//paopao.setLayout(new BorderLayout());
//final Integer index=new Integer(1);
//paopao.pack();
//final GameEngine ge=new GameEngine(0);
//ge.run();
// paopao.getContentPane().add(new JPanel(){
// /**
// * 为了删掉警告
// */
// private static final long serialVersionUID = -5283610764609078407L;
//
// public void paintComponent(Graphics g) {
//
// super.paintComponent(g);
// GlobalVariable.newInstance().put("P",(Graphics2D)g);
//
// //g.fillOval(0,0,100,100);
//
// Vector<Module> allModules=GameContext.i().getModuleContainer().getModules();
//
//
// for(Module module:allModules){
// module.draw();
// }
//
// //File file=new File(getClass().getResource("")+"a/ball_black.png");
// //ge.renderScreen();
// //g.drawImage(new ImageIcon(getClass().getResource("")+"a/ball_black.png").getImage(),40,40,this);
// //g.setColor(Color.black);
// //g.fillOval((int)(Math.random()*300),0, 50,50);
// }
//
// public void paint(Graphics g){
// g.fillOval(0,0,100,100);
// }
//
//
// },BorderLayout.CENTER);
//GameEngine ge=new GameEngine(0);
//ge.run();
//paopao.setVisible(true);
//ge.register(paopao);
//this.getComponents();
//final GamePanel panel=(GamePanel)getContentPane().getComponent(0);
//panel.repaint();
// final GameScreen s=this;
//panel.paintComponent(panel.getGraphics());
new Thread(new Runnable(){
public void run(){
while(true){
try {
//Thread.sleep(RESOLUTION);
//paopao.paintComponents(paopao.getGraphics());
//paopao.paintComponents(paopao.getGraphics());
while(true){
Thread.sleep(RESOLUTION);
//panel.paintComponent(panel.getGraphics());
update(getGraphics());
}
} catch (Exception e) {
}
}
}
}).start();
}
public static void main(String[] args){
//GameScreen.start();
}
}程序刚启动的时候图形显示不出来,但只要一调整下窗口的大小,或者最大化,图形就可以显示了。不知道什么问题呀,郁闷死了。请大家赐教.....
我还碰到过一个JDeskTop,有个地方一定要按循序来。不然也有问题
这种问题很郁闷……