JLabel won't update it's new Text - java

So I am creating a calculator app. When one of the number buttons is clicked, it is supposed to appear on the JLabel. I have added actionListeners to all of my buttons, and when a number button is clicked, the JLabel's text is changed, via the method .setText(). For some reason when i run the program, the JLabel's text doesn't update. So i thought that the text value of the JLbale wasn't being changed, yet when I print the text value of the JLabel on the console, its shows that is has changed. I'm an now stuck. Help would be appreciated
package com.Patel.APSC;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.UIManager;
public class Calculator extends JFrame {
double num1 = 0;
double num2 = 0;
String strNum1;
String strNum2;
String op;
Double answer;
String label = "";
private JButton btnClear;
JLabel lblLabel = new JLabel("");
// constructors
public Calculator() {
// sets up the JFrame
this.setVisible(true);
this.setTitle("Calculator");
this.setResizable(false);
this.setSize(356, 512);
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setBackground(new Color(212, 229, 238));
// sets up all the buttons
JButton btn1 = new JButton("1");
JButton btn2 = new JButton("2");
JButton btn3 = new JButton("3");
JButton btn4 = new JButton("4");
JButton btn5 = new JButton("5");
JButton btn6 = new JButton("6");
JButton btn7 = new JButton("7");
JButton btn8 = new JButton("8");
JButton btn9 = new JButton("9");
JButton btn0 = new JButton("0");
JButton btnAdd = new JButton("+");
JButton btnSubtract = new JButton("-");
JButton btnMultiply = new JButton("*");
JButton btnDivide = new JButton("/");
JButton btnEqual = new JButton("=");
JButton btnClear = new JButton("AC");
btnClear.setBorder(null);
btn1.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn2.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn3.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn4.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn5.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn6.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn7.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn8.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn9.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn0.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btnAdd.setFont(new Font("Mongolian Baiti", Font.PLAIN, 32));
btnSubtract.setFont(new Font("Mongolian Baiti", Font.PLAIN, 32));
btnMultiply.setFont(new Font("Mongolian Baiti", Font.PLAIN, 32));
btnDivide.setFont(new Font("Mongolian Baiti", Font.PLAIN, 32));
btnEqual.setFont(new Font("Mongolian Baiti", Font.PLAIN, 32));
btnClear.setFont(new Font("Times New Roman", Font.PLAIN, 32));
btn1.setLocation(28, 159);
btn2.setLocation(98, 159);
btn3.setLocation(168, 159);
btn4.setLocation(28, 229);
btn5.setLocation(98, 229);
btn6.setLocation(168, 229);
btn7.setLocation(28, 299);
btn8.setLocation(98, 299);
btn9.setLocation(168, 299);
btn0.setLocation(98, 369);
btnAdd.setLocation(265, 369);
btnSubtract.setLocation(265, 299);
btnMultiply.setLocation(265, 229);
btnDivide.setLocation(265, 159);
btnEqual.setLocation(265, 93);
btnClear.setBounds(163, 369, 55, 55);
btn1.setSize(55, 55);
btn2.setSize(55, 55);
btn3.setSize(55, 55);
btn4.setSize(55, 55);
btn5.setSize(55, 55);
btn6.setSize(55, 55);
btn7.setSize(55, 55);
btn8.setSize(55, 55);
btn9.setSize(55, 55);
btn0.setSize(55, 55);
btnAdd.setSize(55, 55);
btnSubtract.setSize(55, 55);
btnMultiply.setSize(55, 55);
btnDivide.setSize(55, 55);
btnEqual.setSize(55, 55);
btn0.setActionCommand("0");
btn1.setActionCommand("1");
btn2.setActionCommand("2");
btn3.setActionCommand("3");
btn4.setActionCommand("4");
btn5.setActionCommand("5");
btn6.setActionCommand("6");
btn7.setActionCommand("7");
btn8.setActionCommand("8");
btn9.setActionCommand("9");
btnAdd.setActionCommand("+");
btnSubtract.setActionCommand("-");
btnMultiply.setActionCommand("*");
ButtonListener listener = new ButtonListener();
btn1.addActionListener(listener);
btn2.addActionListener(listener);
btn3.addActionListener(listener);
btn4.addActionListener(listener);
btn5.addActionListener(listener);
btn6.addActionListener(listener);
btn7.addActionListener(listener);
btn8.addActionListener(listener);
btn9.addActionListener(listener);
btn0.addActionListener(listener);
btnAdd.addActionListener(listener);
btnSubtract.addActionListener(listener);
btnMultiply.addActionListener(listener);
btnDivide.addActionListener(listener);
btnClear.addActionListener(listener);
btnEqual.addActionListener(listener);
this.getContentPane().add(btn0);
this.getContentPane().add(btn1);
this.getContentPane().add(btn2);
this.getContentPane().add(btn3);
this.getContentPane().add(btn4);
this.getContentPane().add(btn5);
this.getContentPane().add(btn6);
this.getContentPane().add(btn7);
this.getContentPane().add(btn8);
this.getContentPane().add(btn9);
this.getContentPane().add(btnAdd);
this.getContentPane().add(btnSubtract);
this.getContentPane().add(btnMultiply);
this.getContentPane().add(btnDivide);
this.getContentPane().add(btnEqual);
this.getContentPane().add(btnClear);
JLabel lblLabel = new JLabel("");
lblLabel.setFont(new Font("Times New Roman", Font.PLAIN, 27));
this.getContentPane().add(lblLabel);
lblLabel.setLocation(43, 31);
lblLabel.setSize(277, 51);
lblLabel.setOpaque(true);
}
public static void main(String[] args) {
Calculator gui = new Calculator();
}
public class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("1")
|| e.getActionCommand().equals("2")
|| e.getActionCommand().equals("3")
|| e.getActionCommand().equals("4")
|| e.getActionCommand().equals("5")
|| e.getActionCommand().equals("6")
|| e.getActionCommand().equals("7")
|| e.getActionCommand().equals("8")
|| e.getActionCommand().equals("9")
|| e.getActionCommand().equals("0")) {
// if a number is typed
lblLabel.setText(e.getActionCommand());
System.out.println(lblLabel.getText());
}
}
}
}

You're calling text.setText(e.getActionCommand()) -- but what is this textfield? It's not your JLabel which is called, lblLabel, and in fact, I can't find a text field within your program, and so I'm surprised that the class even compiles.
I believe that you'll be much better off calling setText on the correct JLabel field: lblLabel.setText(e.getActionCommand())
Side recommendations:
Needless repetition often leads to hard to find bugs, and so you'll want to use arrays or collections and for loops to consolidate your code.
Your gut instinct may be to use a null layout and calling setBounds(...) on your components to place them with absolute positioning, but I'm going suggest that you not do this as this makes for very inflexible GUI's that while they might look good on one platform look terrible on most other platforms or screen resolutions and that are very difficult to update and maintain. Instead you will want to study and learn the layout managers and then nest JPanels, each using its own layout manager to create pleasing and complex GUI's that look good on all OS's.
Your last large if block can be compressed to if ("1234567890".contains(e.getActionCommand()) {
Edit
Your question's edit changes everything. Please avoid these types of changes as they can be very frustrating to us volunteers.
Now I see that you're shadowing the lblLbl variable by declaring it twice, once in the class and once in the constructor, meaning that the class's field is not the JLabel that is being displayed. Solution: declare the variable only once.
so change
public class Calculator {
JLabel lblLabel = new JLabel("");
public Calculator() {
JLabel lblLabel = new JLabel("");
// ...
}
}
to:
public class Calculator {
JLabel lblLabel = new JLabel("");
public Calculator() {
// JLabel lblLabel = new JLabel(""); // don't re-declare
// ...
}
}

Related

Java Gui cannot scroll through scrollPane

I am creating a Gui in java and I wanted to have a list of selectable checkboxes in a smaller pane that allows you to scroll through it. I have it set up but I may have messed up somewhere that it does not allow me to scroll, any help is appreciated.
GUI:
Code:
private void initialize() {
frame = new JFrame();
frame.setResizable(false);
frame.getContentPane().setBackground(new Color(255, 255, 255));
frame.getContentPane().setLayout(null);
frame.setVisible(true);
frame.setSize(801, 500);
JPanel panel_1 = new JPanel();
panel_1.setBorder(null);
panel_1.setBackground(new Color(66, 69, 65));
panel_1.setBounds(0, 0, 194, 483);
frame.getContentPane().add(panel_1);
String[] sports = { "Select a sport", "NBA", "NFL", "NHL", "ATL", "MLB", "NCAA", "PGA", "CKE" }; // list of
panel_1.setLayout(null);
JButton btnNewButton = new JButton("Submit");
btnNewButton.setBounds(52, 382, 89, 25);
panel_1.add(btnNewButton);
btnNewButton.setFont(new Font("Leelawadee UI Semilight", Font.BOLD, 12));
// items
// contained
// in drop
// down
JComboBox comboBox_1 = new JComboBox(sports);
comboBox_1.setBounds(17, 345, 155, 22);
panel_1.add(comboBox_1);
comboBox_1.setMaximumRowCount(10);
comboBox_1.setBackground(new Color(255, 255, 255));
comboBox_1.addActionListener(comboBox_1);
comboBox_1.addActionListener(comboBox_1);
comboBox_1.addActionListener(comboBox_1);
JLabel lblSport = new JLabel("Sport\r\n");
lblSport.setBounds(0, 321, 188, 18);
lblSport.setForeground(Color.WHITE);
panel_1.add(lblSport);
lblSport.setHorizontalAlignment(SwingConstants.CENTER);
lblSport.setFont(new Font("Leelawadee UI Semilight", Font.BOLD, 14));
lblSport.setBackground(SystemColor.activeCaption);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(0, 0, 188, 291);
panel_1.add(scrollPane);
JPanel panel_2_1 = new JPanel();
scrollPane.setViewportView(panel_2_1);
panel_2_1.setToolTipText(
"This is where you input the URL of a gambling site that will be used in the calculator.");
panel_2_1.setBorder(null);
panel_2_1.setBackground(new Color(66, 69, 65));
panel_2_1.setLayout(null);
JLabel lblNewLabel = new JLabel("Sportsbook Selection");
lblNewLabel.setBounds(0, 0, 0, 0);
lblNewLabel.setForeground(Color.WHITE);
panel_2_1.add(lblNewLabel);
lblNewLabel.setFont(new Font("Calibri", Font.PLAIN, 16));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setLabelFor(frame);
lblNewLabel.setBackground(SystemColor.activeCaption);
JCheckBox chckbxNewCheckBox = new JCheckBox("888Bets");
chckbxNewCheckBox.setBounds(6, 43, 89, 23);
chckbxNewCheckBox.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox);
JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Bovada");
chckbxNewCheckBox_2.setBounds(97, 43, 89, 23);
chckbxNewCheckBox_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2);
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("BlueBet");
chckbxNewCheckBox_1.setBounds(6, 69, 89, 23);
chckbxNewCheckBox_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_1);
JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Coral");
chckbxNewCheckBox_3.setBounds(97, 69, 89, 23);
chckbxNewCheckBox_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_3);
JCheckBox chckbxNewCheckBox_4 = new JCheckBox("BoyleSports");
chckbxNewCheckBox_4.setBounds(6, 95, 89, 23);
chckbxNewCheckBox_4.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_4);
JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Circa Sports");
chckbxNewCheckBox_5.setBounds(97, 95, 89, 23);
chckbxNewCheckBox_5.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_5);
JCheckBox chckbxNewCheckBox_6 = new JCheckBox("Betclic");
chckbxNewCheckBox_6.setBounds(6, 121, 89, 23);
chckbxNewCheckBox_6.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_6);
JCheckBox chckbxNewCheckBox_2_1 = new JCheckBox("Casumo");
chckbxNewCheckBox_2_1.setBounds(97, 121, 89, 23);
chckbxNewCheckBox_2_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2_1);
JCheckBox chckbxNewCheckBox_1_1 = new JCheckBox("Betfair");
chckbxNewCheckBox_1_1.setBounds(6, 147, 89, 23);
chckbxNewCheckBox_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_1_1);
JCheckBox chckbxNewCheckBox_3_1 = new JCheckBox("DraftKings");
chckbxNewCheckBox_3_1.setBounds(97, 147, 89, 23);
chckbxNewCheckBox_3_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_3_1);
JCheckBox chckbxNewCheckBox_4_1 = new JCheckBox("BetMGM");
chckbxNewCheckBox_4_1.setBounds(6, 173, 89, 23);
chckbxNewCheckBox_4_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_4_1);
JCheckBox chckbxNewCheckBox_5_1 = new JCheckBox("FanDuel");
chckbxNewCheckBox_5_1.setBounds(97, 173, 89, 23);
chckbxNewCheckBox_5_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_5_1);
JCheckBox chckbxNewCheckBox_7 = new JCheckBox("BetOnline");
chckbxNewCheckBox_7.setBounds(6, 199, 89, 23);
chckbxNewCheckBox_7.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_7);
JCheckBox chckbxNewCheckBox_2_2 = new JCheckBox("FOX Bet");
chckbxNewCheckBox_2_2.setBounds(97, 199, 89, 23);
chckbxNewCheckBox_2_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2_2);
JCheckBox chckbxNewCheckBox_1_2 = new JCheckBox("BetRivers");
chckbxNewCheckBox_1_2.setBounds(6, 225, 89, 23);
chckbxNewCheckBox_1_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_1_2);
JCheckBox chckbxNewCheckBox_3_2 = new JCheckBox("GTbets");
chckbxNewCheckBox_3_2.setBounds(97, 225, 89, 23);
chckbxNewCheckBox_3_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_3_2);
JCheckBox chckbxNewCheckBox_4_2 = new JCheckBox("Bet Victor");
chckbxNewCheckBox_4_2.setBounds(6, 251, 89, 23);
chckbxNewCheckBox_4_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_4_2);
JCheckBox chckbxNewCheckBox_5_2 = new JCheckBox("Intertops");
chckbxNewCheckBox_5_2.setBounds(97, 251, 89, 23);
chckbxNewCheckBox_5_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_5_2);
JCheckBox chckbxNewCheckBox_6_1 = new JCheckBox("BetUS");
chckbxNewCheckBox_6_1.setBounds(6, 277, 89, 23);
chckbxNewCheckBox_6_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_6_1);
JCheckBox chckbxNewCheckBox_2_1_1 = new JCheckBox("Ladbrokes");
chckbxNewCheckBox_2_1_1.setBounds(97, 277, 89, 23);
chckbxNewCheckBox_2_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2_1_1);
JCheckBox chckbxLeovegas = new JCheckBox("LeoVegas");
chckbxLeovegas.setBounds(6, 304, 89, 23);
chckbxLeovegas.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxLeovegas);
JCheckBox chckbxNewCheckBox_2_3 = new JCheckBox("LiveScore");
chckbxNewCheckBox_2_3.setBounds(97, 304, 89, 23);
chckbxNewCheckBox_2_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2_3);
JCheckBox chckbxNewCheckBox_1_3 = new JCheckBox("LowVig");
chckbxNewCheckBox_1_3.setBounds(6, 330, 89, 23);
chckbxNewCheckBox_1_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_1_3);
JCheckBox chckbxNewCheckBox_3_3 = new JCheckBox("Matchbook");
chckbxNewCheckBox_3_3.setBounds(97, 330, 89, 23);
chckbxNewCheckBox_3_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_3_3);
JCheckBox chckbxNewCheckBox_4_3 = new JCheckBox("MarathonkBet ");
chckbxNewCheckBox_4_3.setBounds(6, 356, 89, 23);
chckbxNewCheckBox_4_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_4_3);
JCheckBox chckbxNewCheckBox_5_3 = new JCheckBox("Mr Green");
chckbxNewCheckBox_5_3.setBounds(97, 356, 89, 23);
chckbxNewCheckBox_5_3.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_5_3);
JCheckBox chckbxNewCheckBox_6_2 = new JCheckBox("MyBookie");
chckbxNewCheckBox_6_2.setBounds(6, 382, 89, 23);
chckbxNewCheckBox_6_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_6_2);
JCheckBox chckbxNewCheckBox_2_1_2 = new JCheckBox("Neds");
chckbxNewCheckBox_2_1_2.setBounds(97, 382, 89, 23);
chckbxNewCheckBox_2_1_2.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_2_1_2);
JCheckBox chckbxNewCheckBox_1_1_1 = new JCheckBox("NordicBet");
chckbxNewCheckBox_1_1_1.setBounds(6, 408, 89, 23);
chckbxNewCheckBox_1_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_1_1_1);
JCheckBox chckbxNewCheckBox_3_1_1 = new JCheckBox("PaddyPower");
chckbxNewCheckBox_3_1_1.setBounds(97, 408, 89, 23);
chckbxNewCheckBox_3_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_3_1_1);
JCheckBox chckbxNewCheckBox_4_1_1 = new JCheckBox("PointsBet(AU)");
chckbxNewCheckBox_4_1_1.setBounds(6, 434, 89, 23);
chckbxNewCheckBox_4_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_4_1_1);
JCheckBox chckbxNewCheckBox_5_1_1 = new JCheckBox("PointsBet(US)");
chckbxNewCheckBox_5_1_1.setBounds(97, 434, 89, 23);
chckbxNewCheckBox_5_1_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_5_1_1);
JCheckBox chckbxNewCheckBox_7_1 = new JCheckBox("Pinnacle");
chckbxNewCheckBox_7_1.setBounds(6, 460, 89, 23);
chckbxNewCheckBox_7_1.setFont(new Font("Calibri", Font.PLAIN, 11));
panel_2_1.add(chckbxNewCheckBox_7_1);
I was hoping to make the checkboxes able to be scrolled through.`
See the below runnable code to see one way this can be done using a JDialog for a window and Layout managers. Be sure to read the comments in code. You should be able to adapt the concept to your specific application:
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class SportBookingsDemo {
//Class member variables:
private JDialog dia; // JDialog object (class global):
private JCheckBox[] chks; // JCheckBox object Array (class global):
private JComboBox sportCombo; // JDialog object (class global):
private JButton submit; // JButton object (class global):
// Captions for All JCheckBoxes (class global):
String[] sportsBookNames = {"888Bets", "Bovada", "BlueBet", "Coral", "BoyleSports",
"Circa Sports", "Betclic", "Casumo", "Betfair", "DraftKings",
"BetMGM", "FanDuel", "BetOnline", "FOX Bet", "BetRivers",
"GTbets", "Bet Victor", "Intertops", "BetUS", "Ladbrokes",
"LeoVegas", "LiveScore", "LowVig", "Matchbook", "MarathonkBet",
"Mr Green", "MyBookie", "Neds", "NordicBet", "PaddyPower",
"PointsBet(AU)", "PointsBet(US)", "Pinnacle"};
// ArrayList of String to hold captions for selected checkboxes (class global):
private ArrayList<String> bookings = new ArrayList<>();
// String Variable to hold the selected Sport (class global):
private String sport;
// Constructor:
public SportBookingsDemo() {
// Create the Dialog Window:
createDialog();
// `Submit` button ActionPerformed event:
submit.addActionListener((ActionEvent e) -> {
bookings.clear();
sport = "";
if (sportCombo.getSelectedItem().equals("Select a sport")) {
JOptionPane.showMessageDialog(dia, "You must select a specific Sport!",
"No Sport Selected", JOptionPane.WARNING_MESSAGE);
sportCombo.requestFocus();
return;
}
else {
sport = sportCombo.getSelectedItem().toString();
}
System.out.println("Selected Bookings:");
for (int i = 0; i < chks.length; i++) {
if (chks[i].isSelected()) {
bookings.add(sportsBookNames[i]);
}
}
if (bookings.isEmpty()) {
JOptionPane.showMessageDialog(dia, "You must select at least one Sportsbook!",
"No Sportbook Selected", JOptionPane.WARNING_MESSAGE);
sportCombo.requestFocus();
return;
}
// Display dialog results:
StringBuilder sb = new StringBuilder("");
sb.append("<html><center>Selected bookings for the Sport of:<br><br>");
sb.append("<font size='5', color=blue><b>").append(sport).append("</b></font><br><br></center>");
for (String bks : bookings) {
sb.append("<font size='4', color=green>✓ </font>").append(bks).append("<br>");
}
sb.append("<br></html>");
JOptionPane.showMessageDialog(dia, sb.toString(), "Bookings",
JOptionPane.INFORMATION_MESSAGE);
});
}
// Application entry point...
public static void main(String[] args) {
// App started this way to avoid the need for statics:
new SportBookingsDemo().startApp(args);
}
private void startApp(String[] args) {
// Display dialog window:
java.awt.EventQueue.invokeLater(() -> {
dia.setVisible(true);
});
}
// Method to create Dialog:
private void createDialog() {
dia = new JDialog(); // Initialize JDialog.
dia.setModal(true); // Set dialog to Modal.
dia.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); //Dispose dialog when closed.
dia.setTitle("Sports Book Dialog"); // Set dialog title caption.
dia.setAlwaysOnTop(true); // Dialog will always be on top of other windows.
dia.setSize(280, 390); // Set dialog size.
dia.setResizable(false); // Make dialog non-sizeable.
dia.setLocationRelativeTo(null); // Open dialog window to center screen.
// Decalre and initialize the JDialog's main content panel
JPanel mainPanel = new JPanel();
// Set Horizontal and Vertical Gaps for mainPanel's default FlowLayout.
FlowLayout layout = new FlowLayout();
/* Set Horiz and Vert layout Gaps. The helps ensure the
components in dialog are center aligned as a single
column. */
layout.setHgap(140); layout.setVgap(10);
mainPanel.setLayout(layout); // Apply Layout.
dia.add(mainPanel); // Add mainPanel to dialog Window
/* Declare and initialize a JLabel to display
the CheckBoxes scrollable list display. */
JLabel label_1 = new JLabel("Sportsbook Selection");
// Set the Font, font style, and font size for the title:
label_1.setFont(new Font("Leelawadee UI Semilight", Font.BOLD, 14));
// Set JLabel text Horizontal Alignment to center.
label_1.setHorizontalAlignment(JLabel.CENTER);
mainPanel.add(label_1); // Add title to mainPanel.
/* Declare a JPanel to hold all the checkboxes that
will be added to a JScrollPane within the dialog.
We also ensure a GridLayout of -1 rows (as many
as needed) and 2 columns for the JPanel. */
JPanel chkPanel = new JPanel(new GridLayout(-1, 2));
/* Initialize the chks[] JCheckBox Array to the required
length. This length is actually determined by the number
of elements within the sportsBookNames[] array which
will hereby be considered a `parallel` array to the chks[]
array. Every CheckBox element contained within the chks[]
array will contain a Caption text from the sportsBookNames[]
array at the same index value. */
chks = new JCheckBox[sportsBookNames.length];
/* Iterate through the chks[] array elements and apply
JCheckBox objects to them with text captions derived
from the sportsBookNames[] array at the current
iterated index. Add each chks[] element (JCheckBox)
to the `chkPanel` JPanel. */
for (int i = 0; i < chks.length; i++) {
chks[i] = new JCheckBox(sportsBookNames[i]);
chks[i].setFont(new Font("Calibri", Font.PLAIN, 12));
chkPanel.add(chks[i]);
}
// Add the now filled chkPanel to a JScrollPane (`chkScroll`).
JScrollPane chkScroll = new JScrollPane(chkPanel);
// Set the ScrollPane's Preferred Size we want within te dialog.
chkScroll.setPreferredSize(new Dimension(250, 200));
// Add the ScrollPane (`chkScroll`) to the Main Panel (`mainPanel`).
mainPanel.add(chkScroll);
/* Declare a JLabel to be a title for a Sport type JComboBox
and provide a title: */
JLabel sportLBL = new JLabel("Sport");
// Set the Font, font style, and font size for the title:
sportLBL.setFont(new Font("Leelawadee UI Semilight", Font.BOLD, 14));
// Add the JLabel (`sportLBL`) to the Main Panel (`mainPanel`).
mainPanel.add(sportLBL);
/* Create a JComboBox (`sportCombo`) and fill it with
Sport Types. Sport Type names are contained within
the `sports[]` array. */
String[] sports = {"Select A Sport", "NBA", "NFL", "NHL",
"ATL", "MLB", "NCAA", "PGA", "CKE"};
sportCombo = new JComboBox<>(sports);
sportCombo.setFont(new Font("Leelawadee UI Semilight", Font.PLAIN, 12));
// Set the Preferred Size of the JComboBox (`sportCombo`):
sportCombo.setPreferredSize(new Dimension(120, 25));
// Make sure the ComboBox is non-editable.
sportCombo.setEditable(false);
// Add the JComboBox (`sportCombo`) to the Main Panel (`mainPanel`).
mainPanel.add(sportCombo);
/* Initialize the `submit` JButton and apply the
text caption of "Submit". */
submit = new JButton("Submit");
submit.setFont(new Font("Leelawadee UI Semilight", Font.BOLD, 12));
// Add the JButton (`submit`) to the Main Panel (`mainPanel`).
mainPanel.add(submit);
}
}

How do I position my title on top of the GUI window?

I am new to programming and still learning. I need help in positioning a JLabel "Welcome back" on top of the GUI interface. The label keeps getting stuck in the middle despite my efforts. Feel free to correct any other mistakes shown in the code that I can do better.
public class MainMenu {
public static void main(String[] args) {
JFrame frame = new JFrame("Main Menu");
JPanel panel = new JPanel();
panel.setBounds(30, 80, 400, 570);
panel.setLayout(new GridLayout(3, 2, 15, 15));
panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
JButton meals = new JButton("Meals");
meals.setFont(new Font("Helvetica", Font.BOLD, 24));
meals.setOpaque(true);
JButton reminder = new JButton ("Reminders");
reminder.setFont(new Font("Helvetica", Font.BOLD, 24));
reminder.setOpaque(true);
JButton shop = new JButton ("Shop");
shop.setFont(new Font("Helvetica", Font.BOLD, 24));
shop.setOpaque(true);
JButton sleep = new JButton ("Sleep Timer");
sleep.setFont(new Font("Helvetica", Font.BOLD, 24));
sleep.setOpaque(true);
JButton account = new JButton ("My Account");
account.setFont(new Font("Helvetica", Font.BOLD, 24));
account.setOpaque(true);
JButton aboutus = new JButton ("About Us");
aboutus.setFont(new Font("Helvetica", Font.BOLD, 24));
aboutus.setOpaque(true);
JLabel label = new JLabel("Welcome back!");
label.setLocation(240, 20);
panel.add(meals);
panel.add(reminder);
panel.add(shop);
panel.add(sleep);
panel.add(account);
panel.add(aboutus);
frame.add(panel);
frame.add(label);
frame.setSize(480, 720);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Panels are rearranged on an intermediary Layout-manager(Border)
There are also various solutions based on Layout-used, but the main idea is the same
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainMenu {
public static void main(String[] args) {
JFrame frame = new JFrame("Main Menu");
//define a new layout
frame.setLayout(new BorderLayout());
//panel for label
JPanel topPanel = new JPanel();
JPanel panel = new JPanel();
panel.setBounds(30, 80, 400, 570);
panel.setLayout(new GridLayout(3, 2, 15, 15));
panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
JButton meals = new JButton("Meals");
meals.setFont(new Font("Helvetica", Font.BOLD, 24));
meals.setOpaque(true);
JButton reminder = new JButton ("Reminders");
reminder.setFont(new Font("Helvetica", Font.BOLD, 24));
reminder.setOpaque(true);
JButton shop = new JButton ("Shop");
shop.setFont(new Font("Helvetica", Font.BOLD, 24));
shop.setOpaque(true);
JButton sleep = new JButton ("Sleep Timer");
sleep.setFont(new Font("Helvetica", Font.BOLD, 24));
sleep.setOpaque(true);
JButton account = new JButton ("My Account");
account.setFont(new Font("Helvetica", Font.BOLD, 24));
account.setOpaque(true);
JButton aboutus = new JButton ("About Us");
aboutus.setFont(new Font("Helvetica", Font.BOLD, 24));
aboutus.setOpaque(true);
JLabel label = new JLabel("Welcome back!");
panel.add(meals);
panel.add(reminder);
panel.add(shop);
panel.add(sleep);
panel.add(account);
panel.add(aboutus);
topPanel.add(label);
topPanel.setSize(200, 30);
//rearrange panels on frame
frame.add(topPanel, BorderLayout.NORTH);
frame.add(panel, BorderLayout.CENTER);
frame.setSize(480, 720);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output:

can not refer a value to a radiobutton

i write a convert temperature code using radiobutton, but when i use actionListener to print the value to a label, it show "Cannot refer to the non-final local variable valueto defined in an enclosing scope"
can some one show me the problem and how to fix it? (also sorry for my English)
the Radiobutton
JRadioButton Cbutton = new JRadioButton("Celsius");
Fbutton.setFont(new Font("Tahoma", Font.PLAIN, 12));
Fbutton.setBounds(10, 40, 109, 23);
contentPane.add(Cbutton);
JRadioButton Fbutton2 = new JRadioButton("Fahrenheit");
Fbutton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText(String.valueOf(valueto));
}
});
i use this to convert
if(Fbutton.isSelected()&&Cbutton2.isSelected()){
value=F;
valueto=(F-32)/1.8;
}else if(Fbutton.isSelected()&&Kbutton2.isSelected()){
value=F;
valueto=(F+459.67)*5/9;
}else if(Cbutton.isSelected()&&Fbutton2.isSelected()){
value=C;
valueto=C*1.8+32;
}else if(Cbutton.isSelected()&&Kbutton2.isSelected()){
value=C;
valueto=C+273.15;
}else if(Kbutton.isSelected()&&Cbutton2.isSelected()){
value=K;
valueto=K-273.15;
}else if(Kbutton.isSelected()&&Fbutton2.isSelected()){
value=K;
valueto=K*9.5-459.67;
}
Edit : i declare valueto at the bottom of the class
double value = 0;
double valueto = 0;
double F = 0, C = 0, K = 0;
it ask me to add final to "double valueto", but when i add it the valueto in "if" become error
The Whole code
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
public class CtoKtoF extends JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CtoKtoF frame = new CtoKtoF();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* #return
*/
public CtoKtoF() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 303);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
double value = 0 ;
double valueto = 0;
double F = 0, C = 0, K = 0;
Border border = LineBorder.createGrayLineBorder();//make border for Jlabel
final JLabel label = new JLabel("New label");
label.setFont(new Font("Tahoma", Font.PLAIN, 12));
label.setBounds(10, 228, 220, 22);
label.setBorder(border);
contentPane.add(label);
JLabel lblNewLabel = new JLabel("Convert from");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblNewLabel.setBounds(10, 11, 92, 22);
contentPane.add(lblNewLabel);
JRadioButton Fbutton = new JRadioButton("Fahrenheit");
Fbutton.setFont(new Font("Tahoma", Font.PLAIN, 12));
Fbutton.setBounds(10, 40, 109, 23);
//Fbutton.setActionCommand("F");
contentPane.add(Fbutton);
JRadioButton Cbutton = new JRadioButton("Celcius");
Cbutton.setFont(new Font("Tahoma", Font.PLAIN, 12));
Cbutton.setBounds(121, 40, 109, 23);
//Cbutton.setActionCommand("C");
contentPane.add(Cbutton);
JRadioButton Kbutton = new JRadioButton("Kelvin");
Kbutton.setFont(new Font("Tahoma", Font.PLAIN, 12));
Kbutton.setBounds(232, 40, 109, 23);
//Kbutton.setActionCommand("K");
contentPane.add(Kbutton);
JLabel lblEnterNumericTemperature = new JLabel("Enter Numeric Temperature");
lblEnterNumericTemperature.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblEnterNumericTemperature.setBounds(10, 70, 238, 22);
contentPane.add(lblEnterNumericTemperature);
textField = new JTextField();
textField.setFont(new Font("Tahoma", Font.PLAIN, 12));
textField.setBounds(10, 103, 220, 22);
textField.setText(String.valueOf(value));
contentPane.add(textField);
textField.setColumns(10);
JRadioButton Fbutton2 = new JRadioButton("Fahrenheit");
Fbutton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText(String.valueOf(valueto));
}
});
Fbutton2.setFont(new Font("Tahoma", Font.PLAIN, 12));
Fbutton2.setBounds(10, 165, 109, 23);
//Fbutton2.setActionCommand("F2");
contentPane.add(Fbutton2);
JRadioButton Cbutton2 = new JRadioButton("Celcius");
Cbutton2.setFont(new Font("Tahoma", Font.PLAIN, 12));
Cbutton2.setBounds(121, 165, 109, 23);
//Cbutton2.setActionCommand("C2");
contentPane.add(Cbutton2);
JRadioButton Kbutton2 = new JRadioButton("Kelvin");
Kbutton2.setFont(new Font("Tahoma", Font.PLAIN, 12));
Kbutton2.setBounds(232, 165, 109, 23);
//Kbutton2.setActionCommand("K2");
contentPane.add(Kbutton2);
ButtonGroup group1 = new ButtonGroup();
group1.add(Fbutton);
group1.add(Kbutton);
group1.add(Cbutton);
ButtonGroup group2 = new ButtonGroup();
group2.add(Fbutton2);
group2.add(Cbutton2);
group2.add(Kbutton2);
/*Fbutton.addActionListener(this);
Cbutton.addActionListener(this);
Kbutton.addActionListener(this);
Fbutton2.addActionListener(this);
Cbutton2.addActionListener(this);
Kbutton2.addActionListener(this);*/
//boolean checked = Fbutton.getState();
JLabel lblConvertTo = new JLabel("Convert to");
lblConvertTo.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblConvertTo.setBounds(10, 136, 92, 22);
contentPane.add(lblConvertTo);
JLabel lblComparableTemperatureIs = new JLabel("Comparable Temperature is");
lblComparableTemperatureIs.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblComparableTemperatureIs.setBounds(10, 195, 238, 22);
contentPane.add(lblComparableTemperatureIs);
if(Fbutton.isSelected()&&Cbutton2.isSelected()){
value=F;
valueto=(F-32)/1.8;
}else if(Fbutton.isSelected()&&Kbutton2.isSelected()){
value=F;
valueto=(F+459.67)*5/9;
}else if(Cbutton.isSelected()&&Fbutton2.isSelected()){
value=C;
valueto=C*1.8+32;
}else if(Cbutton.isSelected()&&Kbutton2.isSelected()){
value=C;
valueto=C+273.15;
}else if(Kbutton.isSelected()&&Cbutton2.isSelected()){
value=K;
valueto=K-273.15;
}else if(Kbutton.isSelected()&&Fbutton2.isSelected()){
value=K;
valueto=K*9.5-459.67;
}
}
}

Something that I insert on the frame doesnt exist when I run it

Im trying to make a game.
I have a frame and insert jbutton jlabel jtextfield on the frame and the frame has a background.
But now it doesnt appear.
Why isnt buttons etc visible? Can you fix these codes?
public class NewPlayer extends JFrame {
public NewPlayer() {
JLabel backGround = new JLabel(new ImageIcon("images\\fiha2taban2.png"));
setTitle("FiHa");
setSize(750, 550);
getContentPane().add(backGround);
setLocationRelativeTo(null); // Center the frame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
setIconImage(Toolkit.getDefaultToolkit().getImage("images\\iconfh.png"));
Color renk=new Color(255,250,155);
// Create two labels and set their components
JLabel label1= new JLabel("NEW PLAYER !");
label1.setBounds(220,200,300,40);
this.add(label1);
label1.setFont(new Font("Times New Roman", Font.BOLD , 40));
JLabel label2= new JLabel("Please enter your name: ");
label2.setBounds(270,290,249,40);
this.add(label2);
label2.setFont(new Font("Times New Roman", Font.BOLD , 20));
// Create a text field and set its components
JTextField txtField = new JTextField("", 20);
txtField.setBounds(220,335,300,40);
this.add(txtField);
txtField.setFont(new Font("Times New Roman", Font.BOLD , 16));
// Create a button and set its components
JButton button1 = new JButton("OKAY");
button1.setBounds(315,396,110,40);
this.add(button1);
button1.setFont(new Font("Times New Roman", Font.BOLD , 16));
button1.setBackground(renk);
}
}
}

Populate a JComboBox using SQL

I am currently doing a diploma course in Java and for our project we have to create a Restaurant Calculator(See screenshot), I have the majority of the GUI done but I am having great difficulty with the SQL. I have never used SQL before so I'm not 100% certain what to do. I understand how it works but I can't even run the SQL file that the college supplied us in MySQL. Any help with this would be greatly appreciated as I am really struggling with this. I have had this GUI done the past 2 weeks and have been searching online for help but cannot get my head around it
Code is below...
import java.awt.Container;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RestaurantCalculator {
private static JTextField TotalText;
private static JTextField TaxText;
private static JTextField Table;
private static JTextField Sub;
private static JTextField WName;
private static JComboBox BevMenu;
private static JComboBox AppMenu;
private static JComboBox MainMenu;
private static JComboBox DesMenu;
public static void testFun(String myName){
TotalText.setText(myName);
}
public static void addComponentsToPane(Container pane){
pane.setLayout(null);
Border border = BorderFactory.createLoweredBevelBorder();
Border button = BorderFactory.createRaisedBevelBorder();
JLabel Welcome = new JLabel("Restaurant");
Welcome.setBounds(250, 5, 150, 100);
Welcome.setFont(new Font("Arial Black", Font.BOLD, 20));
JLabel Waiter = new JLabel("Waiter Information");
Waiter.setBounds(100, 100, 200, 100);
Waiter.setFont(new Font("Arial Black", Font.BOLD, 14));
JLabel Tableno = new JLabel("Table number:");
Tableno.setBounds(120, 130, 200, 100);
Tableno.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel WaiterName = new JLabel("Waiter Name:");
WaiterName.setBounds(120, 160, 200, 100);
WaiterName.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel MenuItems = new JLabel("Menu Items");
MenuItems.setBounds(100, 220, 150, 100);
MenuItems.setFont(new Font("Arial Black", Font.BOLD, 14));
JLabel Beverage = new JLabel("Beverage:");
Beverage.setBounds(120, 250, 200, 100);
Beverage.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel Appetizer = new JLabel("Appetizer:");
Appetizer.setBounds(120, 280, 200, 100);
Appetizer.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel MainCourse = new JLabel("Main Course:");
MainCourse.setBounds(120, 310, 200, 100);
MainCourse.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel Dessert = new JLabel("Dessert:");
Dessert.setBounds(120, 340, 200, 100);
Dessert.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel SubTotal = new JLabel("Sub Total:");
SubTotal.setBounds(120, 440, 200, 100);
SubTotal.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel Tax = new JLabel("Tax:");
Tax.setBounds(120, 470, 200, 100);
Tax.setFont(new Font("Arial Black", Font.BOLD, 12));
JLabel Total = new JLabel("Total:");
Total.setBounds(120, 500, 200, 100);
Total.setFont(new Font("Arial Black", Font.BOLD, 12));
Table = new JTextField(10);
Table.setBounds(290, 171, 150, 20);
Table.setBorder(border);
WName = new JTextField(11);
WName.setBounds(290, 201, 150, 20);
WName.setBorder(border);
Sub = new JTextField(10);
Sub.setBounds(260,482,150, 20);
Sub.setBorder(border);
Sub.setEditable(false);
TotalText = new JTextField(10);
TotalText.setBounds(260,545,150, 20);
TotalText.setBorder(border);
TotalText.setEditable(false);
TaxText = new JTextField(10);
TaxText.setBounds(260,515,150, 20);
TaxText.setBorder(border);
TaxText.setEditable(false);
BevMenu = new JComboBox();
BevMenu.setBounds(290, 295, 180, 20);
AppMenu = new JComboBox();
AppMenu.setBounds(290, 325, 180, 20);
MainMenu = new JComboBox();
MainMenu.setBounds(290, 355, 180, 20);
DesMenu = new JComboBox();
DesMenu.setBounds(290, 385, 180, 20);
JButton calculateJButton;
calculateJButton = new JButton( "Calculate Bill" );
calculateJButton.setBounds(250,425, 170, 30);
calculateJButton.setBorder(button);
pane.add(Welcome);
pane.add(Waiter);
pane.add(Tableno);
pane.add(WaiterName);
pane.add(MenuItems);
pane.add(Beverage);
pane.add(Appetizer);
pane.add(MainCourse);
pane.add(Dessert);
pane.add(SubTotal);
pane.add(Tax);
pane.add(Total);
pane.add(Table);
pane.add(WName);
pane.add(Sub);
pane.add(TaxText);
pane.add(TotalText);
pane.add(calculateJButton);
pane.add(BevMenu);
pane.add(AppMenu);
pane.add(MainMenu);
pane.add(DesMenu);
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Restaurant Bill Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set up the content pane.
addComponentsToPane(frame.getContentPane());
//Size and display the window.
Insets insets = frame.getInsets();
frame.setSize(600 + insets.left + insets.right,
700 + insets.top + insets.bottom);
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
String theBest = "test";
testFun(theBest);
}
});
}

Categories

Resources