I am very new to java gui and was wondering how to not only put the text at the center, but the center of the center. In other words I want the text in the middle of the screen. I do not want to use a JTextField, I just want to put a JLabel in the center of the panel. I have put in bold the two lines of code that I am working with. Here is the code.
import java.awt.*;*
*import java.awt.event.*;
import javax.swing.*;*
*public class mario {*
*/**
*@param args the command line arguments*
/
public static void main(String[] args) {
// TODO code application logic here
EventQueue.invokeLater(new Runnable()
{
public void run()
{
QuizFrame frame = new QuizFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class QuizFrame extends JFrame
{
public QuizFrame()
{
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
JButton button1 = new JButton("one");
JButton button2 = new JButton("two");
JButton button3 = new JButton("three");
JButton button4 = new JButton("four");
QuizPanel = new JPanel();
QuizPanel.add(button1);
QuizPanel.add(button2);
QuizPanel.add(button3);
QuizPanel.add(button4);
add(QuizPanel,BorderLayout.SOUTH);
*QuizLabel = new JLabel("This is a test");*
*add(QuizLabel,BorderLayout.CENTER);*
}
private JPanel QuizPanel;
private JLabel QuizLabel;
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
}