import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gui extends JFrame
{
private JFrame window = new JFrame();
private JButton but[] = new JButton[9];
public Gui()
{
window.setSize(300,400);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(4, 3));
JLabel txt = new JLabel("Will you dare?", JLabel.CENTER);
txt.setLayout(new GridLayout(1, 1));
txt.setHorizontalTextPosition(JLabel.CENTER);
txt.setFont(new Font("Serif", Font.PLAIN, 21));
window.add(txt);
for(int i = 0; i < 9; i++)
{
but[i] = new JButton();
window.add(but[i]);
}
window.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
}
}
I am Java noob, so, can you tell me, why “Will you dare” text doesn’t appear in one line? Can you tell me how you found the solution, so other time I also will be able to do that by myself.
Wild guess here, but I’m thinking you want something like: