Kłopot z widocznością menu.

0
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

public class Quiz extends JFrame implements ActionListener {
	private static final String Quiz = null;
	private JMenuBar menuBar = new JMenuBar();
	private JMenu Gra = new JMenu("Gra");
	private JFrame frame = new JFrame("Quiz");

	Image dbImage;
	Graphics dbg;

	public Quiz() {
		// konstruktory
		Container c = this.getContentPane();
		Container d = new Container();
		d.setLayout(new GridLayout());
		c.setLayout(new BorderLayout());
		c.add(d, BorderLayout.SOUTH);
		Gra.addActionListener(this);
		Gra.setForeground(Color.red);
		this.setSize(new Dimension(650, 650));
		this.setAlwaysOnTop(true);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Quiz");
		this.setBackground(Color.black);
		this.setJMenuBar(menuBar);

		
		
		menuBar.add(Gra);

	}

	// voids
	public void startGame() {

	}

	public void stopGame() {

	}

	public void resumeGame() {

	}

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

	}

	public static void main(String[] args) {
		Quiz Quiz = new Quiz();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

	}
}
 

Mam już pewien problem na początku programu i nie wiem w którym miejscu jest błąd.Po uruchomieniu mam tło na czarno tak jak chciałem ale nie widać menu.Dopiero jaj kliknę w lewy górny róg to pojawia się przycisk gra.Jak rozwiązać ten problem?

0

Utworzyłeś obiekt frame typu JFrame, ale nie wiedzę abyś go używał. Spróbuj wykorzystać frame i powinno to zadziałać.
Jeżeli dalej nie będziesz wiedział co zrobić to pisz, postaram się pomoc w miarę możliwości.

0
 import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
 
public class Quiz extends JFrame implements ActionListener {
    private static final String Quiz = null;
    private JMenuBar menuBar = new JMenuBar();
    private JMenu Gra = new JMenu("Gra");
    private JMenu Pomoc = new JMenu("Pomoc");
    private JMenuItem Nowa = new JMenuItem("Nowa");
    private JMenuItem Stop = new JMenuItem("Stop");
    private JMenuItem Wznów = new JMenuItem("Wznów");
    private JMenuItem Zakończ = new JMenuItem("Zakończ");
    private JFrame frame = new JFrame("Quiz");
 
 
    Image dbImage;
    Graphics dbg;
 
    public Quiz() {
        // konstruktory
        Container c = this.getContentPane();
        Container d = new Container();
        d.setLayout(new GridLayout());
        c.setLayout(new BorderLayout());
        c.add(d, BorderLayout.SOUTH);
        Gra.addActionListener(this);
        Gra.setForeground(Color.red);
        Pomoc.addActionListener(this);
        Pomoc.setForeground(Color.red);
        Nowa.setForeground(Color.red);
        Stop.setForeground(Color.red);
        Wznów.setForeground(Color.red);
        Zakończ.setForeground(Color.red);
        this.setSize(new Dimension(650, 650));
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Quiz");
        this.setJMenuBar(menuBar);
        setBackground(Color.black);
 
 
 
 
        menuBar.add(Gra);
        Gra.add(Nowa);
        Gra.add(Stop);
        Gra.add(Wznów);
        Gra.add(Zakończ);
        menuBar.add(Pomoc);
 
    }
 
    // voids
    public void startGame() {
 
    }
 
    public void stopGame() {
 
    }
 
    public void resumeGame() {
 
    }
 
    public void paint(Graphics g) {
        dbImage = createImage(getWidth(), getHeight());
        dbg = dbImage.getGraphics();
        g.drawImage(dbImage, 0, 0, this);
        super.paint(g); 
 
    }
 
    private void draw(Graphics dbg2) {
        // TODO Auto-generated method stub
 
    }
 
    public static void main(String[] args) {
        Quiz Quiz = new Quiz();
    }
 
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
 
    }
} 

takie coś zrobiłem po podpowiedzi innej osoby tera widać menu ale jak dam set.Background to znika nazwa Pomoc i nie ma koloru tla ;/

0

Jeżeli chcesz pokolorować "środek" to:

this.getContentPane().setBackground(Color.BLACK);
0

Dałem rozwiązanie w drugim wątku (tym z działu Java, który wylądował w koszu).
____(przeklejone z wątku z kosza - @furious programming)

Z czego się uczysz Swinga? Kod jest bardzo zły, zmień podręcznik.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.JPanel;
 
public class Quiz extends JFrame implements ActionListener {
    //private static final String Quiz = null;
    private JMenuBar menuBar = new JMenuBar();
    private JMenu Gra = new JMenu("Gra");
    private JMenu Pomoc = new JMenu("Pomoc");
    private JMenuItem Nowa = new JMenuItem("Nowa");
    private JMenuItem Stop = new JMenuItem("Stop");
    private JMenuItem Wznów = new JMenuItem("Wznów");
    private JMenuItem Zakończ = new JMenuItem("Zakończ");
    //private JFrame frame = new JFrame("Quiz");
 
 
    //Image dbImage;
    //Graphics dbg;
 
    public Quiz() {
        // konstruktory
        //Container c = this.getContentPane();
        JPanel blackPanel = new JPanel();
        blackPanel.setBackground(Color.BLACK);
        blackPanel.setPreferredSize(new Dimension(650,650));
        //Container d = new Container();
        //d.setLayout(new GridLayout());
        //c.setLayout(new BorderLayout());
        add(blackPanel, BorderLayout.SOUTH);
        Gra.addActionListener(this);
        Gra.setForeground(Color.red);
        Pomoc.addActionListener(this);
        Pomoc.setForeground(Color.red);
        Nowa.setForeground(Color.red);
        Stop.setForeground(Color.red);
        Wznów.setForeground(Color.red);
        Zakończ.setForeground(Color.red);
        //this.setSize(new Dimension(650, 650));
        
        pack();
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Quiz");
        setJMenuBar(menuBar);
        setBackground(Color.black);
 
 
 
 
        menuBar.add(Gra);
        Gra.add(Nowa);
        Gra.add(Stop);
        Gra.add(Wznów);
        Gra.add(Zakończ);
        menuBar.add(Pomoc);
        setVisible(true);
 
    }
 
    // voids
    public void startGame() {
 
    }
 
    public void stopGame() {
 
    }
 
    public void resumeGame() {
 
    }
 
    public static void main(String[] args) {
        new Quiz();
    }
 
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
 
    }
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1