Jump to content

Recommended Posts

Posted

Olá pessoal

Bom ano a todos antes de mais.

No meu trabalho estou como um pequeno problema em que o menu não me aparece, devia mas não aparece, alguma coisa está a faltar?

package canvasgmc;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class Jogo extends JFrame
{
private static final long serialVersionUID = 1L;
private Image dbImage;
private Graphics dbg;
public ArrayList<Alvos> bugs = new ArrayList<>();
static Canhao s1 = new Canhao();


public Jogo()
{
 //Menu e Submenu
 JMenuBar menubar = new JMenuBar();
 JMenu fic = new JMenu("Ficheiro");
 JMenuItem abrir = new JMenuItem("Abrir");
 JMenuItem novo = new JMenuItem("Novo");
 JMenuItem sair = new JMenuItem("Sair");
 fic.add(abrir);
 fic.add(novo);
 fic.add(sair);
 menubar.add(fic);
 setJMenuBar(menubar);

 //Eventos com o teclado
 addKeyListener(new AL());

 //Objetos na janela
 bugs.add(new Alvos(50, 50 , 70, 70,"imagens/bug.gif"));
bugs.add(new Alvos(145, 50 , 70, 70,"imagens/bug1.gif"));
bugs.add(new Alvos(225, 50 , 70, 70,"imagens/bug.gif"));
bugs.add(new Alvos(305, 50 , 70, 70,"imagens/bug1.gif"));
bugs.add(new Alvos(385, 50 , 70, 70,"imagens/bug.gif"));
bugs.add(new Alvos(480, 50 , 70, 70,"imagens/bug.gif"));
bugs.add(new Alvos(60, 100 , 50, 50,"imagens/bug1.gif"));
bugs.add(new Alvos(155, 100 , 50, 50,"imagens/bug.gif"));
bugs.add(new Alvos(235, 100 , 50, 50,"imagens/bug1.gif"));
bugs.add(new Alvos(315, 100 , 50, 50,"imagens/bug.gif"));
bugs.add(new Alvos(395, 100 , 50, 50,"imagens/bug1.gif"));
bugs.add(new Alvos(490, 100 , 50, 50,"imagens/bug.gif"));

}

@Override
public void paint(Graphics g){
 dbImage = createImage(getWidth(), getHeight());
 dbg = dbImage.getGraphics();
 paintComponent(dbg);
 g.drawImage(dbImage, 0, 0, this);
}

public void paintComponent(Graphics g){
 //Desenha o objeto canhoa
 s1.desenho(g);
 repaint();
 //Desenha os bugs
 for(Alvos bg: bugs)
 {
	 bg.desenho(g);
 }
}

public class AL extends KeyAdapter {
 @Override
 public void keyPressed(KeyEvent e){
	 s1.keyPressed(e);
 }
 @Override
 public void keyReleased(KeyEvent e){
	 s1.keyReleased(e);
 }
}

public static void main(String[] args) {

 Jogo j = new Jogo();
 j.setSize(600,400);
 j.setTitle("2012/2013");
 j.setBackground(Color.WHITE);
 j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 j.setResizable(false);
 j.setVisible(true);
 //Threads
 Thread canhao = new Thread(s1);
 canhao.start();
}
}

Agradecia que outros verificassem...eu não vejo 🙂

gmc11

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.