In this code I have a Button1
, where I tried to set the size of 100,400 (I'm going to add more buttons). Although when I run the application the Button is just big enough for the text "Empty Task" to fit.
I would also like to add a title, not a title for the application which I've already done but instead I would like to add a title above the button that says Grocery List in bold letters.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Frame extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new Frame().setVisible(true);
}
public Frame() {
super("GroceryList");
setSize(500, 850);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
JButton Button1 = new JButton("Empty task");
setResizable(false);
Button1.setSize(400, 100);
setVisible(true);
add(Button1);
}
public void Button1() {
setVisible(true);
}
}