Related
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);
}
}
I want to create a simple profile information page with JFrame and contentPane. I added all the components correctly. But I cant set their location. How can i set it? I used setBoundary() method bur it doesnt work.
My Anket.java class is:
import java.awt.*;
import javax.swing.*;
public class Anket {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(600, 300));
frame.setTitle("Profile Information");
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.GRAY);
JRadioButton rdbtnNewRadioButton = new JRadioButton("Age(10-20)");
rdbtnNewRadioButton.setBounds(412, 50, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton);
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("Age(21-30)");
rdbtnNewRadioButton.setBounds(412, 20, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_1);
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("Age(31-40)");
rdbtnNewRadioButton.setBounds(412, 30, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_2);
JRadioButton rdbtnNewRadioButton_3 = new JRadioButton("Age(41-50)");
rdbtnNewRadioButton.setBounds(412, 40, 50, 20);
frame.getContentPane().add(rdbtnNewRadioButton_3);
JLabel lblNewLabel = new JLabel("PLEASE ENTER YOUR INFORMATION");
lblNewLabel.setBounds(149, 0, 182, 14);
frame.getContentPane().add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Enter Your Name");
lblNewLabel_1.setBounds(127, 25, 86, 14);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Enter Your Lastname");
lblNewLabel_2.setBounds(272, 25, 100, 14);
frame.getContentPane().add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Enter Your Height");
lblNewLabel_3.setBounds(127, 103, 86, 14);
frame.getContentPane().add(lblNewLabel_3);
JTextField textField = new JTextField();
textField.setBounds(216, 100, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
JTextField textField_1 = new JTextField();
textField_1.setBounds(127, 48, 86, 20);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JTextField textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(412, 48, 86, 20);
frame.getContentPane().add(textField_2);
JLabel lblNewLabel_4 = new JLabel(new ImageIcon("C:/Users/PC/eclipse-workspace/Project/src/Berguzar.jpg"));
lblNewLabel_4.setBounds(10, 21, 100, 85);
frame.getContentPane().add(lblNewLabel_4);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
}
}
The program doesnt have any error. How can i fix this problem?
My output screen is:
output
You should replace
Container contentPane = frame.getContentPane();
contentPane.setBackground(Color.GRAY);
with
JPanel contentPane = new JPanel(null); // The null is important
contentPane.setBackground(Color.GRAY);
frame.setContentPane(contentPane); // each time you change the content pane you need to revalidate the jframe (frame.setVisible(true) also revalidate the jframe so in this case it is not needed to revalidate the jframe)
I'm working on a group project with my friends for a school assignment. Unfortunately, one of my group members made this program which was much worse before (I tried to fix most of the main issues). Only problem now is, the program doesn't load all of the text on the right, instead leaving ellipses (...).
I've tried modifying and removing setBounds, setSize, and contentPane, yet all those proved ineffective. I'm fairly new to Java all round, so please do go easy on my inexperience.
public class HomeMenu extends JFrame {
private JPanel contentPane;
private JTextField textField;
public HomeMenu() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1366, 768);
setBounds(100, 100, 954, 712);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
setBackground(new Color(255, 255, 255));
getContentPane().setLayout(null);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(Color.BLACK);
panel.setForeground(Color.WHITE);
panel.setBounds(0, 0, 236, 671);
getContentPane().add(panel);
panel.setLayout(null);
JPanel panel_3 = new JPanel();
panel_3.setBounds(44, 5, 1, 1);
panel.add(panel_3);
panel_3.setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(0, 0, 102));
panel_1.setBounds(233, 240, 705, 431);
getContentPane().add(panel_1);
panel_1.setLayout(null);
JPanel panel_6 = new JPanel();
panel_6.setBackground(SystemColor.controlDkShadow);
panel_6.setBounds(307, 235, 285, 164);
panel_1.add(panel_6);
JLabel lblWED = new JLabel("Weddings\r\n");
panel_6.add(lblWED);
lblWED.setForeground(Color.WHITE);
lblWED.setFont(new Font("Sitka Subheading", Font.PLAIN, 23));
lblWED.setBackground(Color.WHITE);
JLabel lblNewLabel_4 = new JLabel("");
panel_6.add(lblNewLabel_4);
lblNewLabel_4.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index2.jpg"));
JPanel panel_4 = new JPanel();
panel_4.setBackground(SystemColor.controlDkShadow);
panel_4.setBounds(43, 25, 189, 298);
panel_1.add(panel_4);
JLabel lblBirthdayPartiesl = new JLabel("Birthday Partiesl");
panel_4.add(lblBirthdayPartiesl);
lblBirthdayPartiesl.setFont(new Font("Snap ITC", Font.PLAIN, 18));
lblBirthdayPartiesl.setForeground(Color.WHITE);
lblBirthdayPartiesl.setBackground(Color.WHITE);
JLabel lblNewLabel_3 = new JLabel("");
panel_4.add(lblNewLabel_3);
lblNewLabel_3.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index.jpg"));
JLabel lblWeDoIt = new JLabel("WE DO nothing at ALL !");
lblWeDoIt.setBounds(68, 359, 212, 40);
panel_1.add(lblWeDoIt);
lblWeDoIt.setForeground(Color.WHITE);
lblWeDoIt.setFont(new Font("Tahoma", Font.PLAIN, 28));
lblWeDoIt.setBackground(Color.WHITE);
JPanel panel_5 = new JPanel();
panel_5.setBounds(297, 25, 358, 185);
panel_1.add(panel_5);
panel_5.setBackground(SystemColor.controlDkShadow);
JLabel lblMeetings = new JLabel("Meetings");
panel_5.add(lblMeetings);
lblMeetings.setForeground(Color.WHITE);
lblMeetings.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblMeetings.setBackground(Color.WHITE);
JLabel lblNewLabel_6 = new JLabel("");
panel_5.add(lblNewLabel_6);
lblNewLabel_6.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_index(1)"));
JLabel lblNewLabel_5 = new JLabel("");
panel_5.add(lblNewLabel_5);
lblNewLabel_5.setIcon(new ImageIcon("C:\\Users\\18060327\\Desktop\\index 3.jpg"));
JPanel panel_2 = new JPanel();
panel_2.setBounds(235, 54, 703, 188);
contentPane.add(panel_2);
panel_2.setBackground(new Color(204, 204, 204));
panel_2.setLayout(null);
JLabel lblNewLabel = new JLabel("ShadEvents");
lblNewLabel.setFont(new Font("Segoe UI Light", Font.PLAIN, 36));
lblNewLabel.setBounds(61, 24, 286, 58);
panel_2.add(lblNewLabel);
JLabel label = new JLabel("Here to make your life harder");
label.setFont(new Font("Segoe UI Light", Font.PLAIN, 13));
label.setBounds(78, 84, 188, 16);
panel_2.add(label);
textField = new JTextField();
textField.setBounds(297, 11, 123, 24);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("");
lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\icons8-user-24.png"));
lblNewLabel_2.setBounds(851, 11, 29, 32);
contentPane.add(lblNewLabel_2);
JLabel lblUser = new JLabel("Welcome!"); //fix this user shit //unfixable
lblUser.setBounds(890, 19, 38, 24);
contentPane.add(lblUser);
lblUser.setFont(new Font("Segoe UI Light", Font.PLAIN, 15));
JLabel lblNewLabel_1 = new JLabel();
lblNewLabel_1.setBounds(258, 11, 29, 24);
contentPane.add(lblNewLabel_1);
lblNewLabel_1.setBackground(Color.BLUE);
lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\HP\\Downloads\\groupwork_src_icons8-search-24.png"));
}
}
Instead of "WE DO nothin..." and "Wel..." (at the top right), it should display "WE DO nothing at ALL!" (Also, do let me know if the code doesn't work.)
I'm trying to call a method that opens a new existing frame, but all I get is an empty frame without content.
This is the code that calls the function when a button is preesed:
JButton btnPersonalInfo = new JButton("Personal Info");
btnPersonalInfo.setBounds(10, 5, 120, 23);
btnPersonalInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame PersonalInfo = new JFrame("Personal Info");
PersonalInfo content = new PersonalInfo();
PersonalInfo.setContentPane(content);
PersonalInfo.setSize(700,700);
PersonalInfo.setLocation(100,15);
PersonalInfo.setDefaultCloseOperation( JFrame.HIDE_ON_CLOSE );
PersonalInfo.setResizable(false);
PersonalInfo.setVisible(true);
}
});
panel_1.add(btnPersonalInfo);
This is how I initialize the PersonalInfo function:
public PersonalInfo() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblPersonalInfo = new JLabel("Personal Information");
lblPersonalInfo.setFont(new Font("Arial", Font.BOLD, 16));
lblPersonalInfo.setBounds(110, 11, 185, 14);
panel.add(lblPersonalInfo);
JLabel lblFullName = new JLabel("Full Name");
lblFullName.setBounds(10, 36, 58, 14);
panel.add(lblFullName);
JLabel lblNationality = new JLabel("Nationality");
lblNationality.setBounds(10, 61, 78, 14);
panel.add(lblNationality);
JLabel lblDateBirth = new JLabel("Date of Birth");
lblDateBirth.setBounds(10, 86, 78, 14);
panel.add(lblDateBirth);
JLabel lblGender = new JLabel("Gender");
lblGender.setBounds(10, 111, 46, 14);
panel.add(lblGender);
JLabel lblAddress = new JLabel("Address");
lblAddress.setBounds(10, 164, 58, 14);
panel.add(lblAddress);
JLabel lblMobile = new JLabel("Mobile");
lblMobile.setBounds(10, 189, 46, 14);
panel.add(lblMobile);
JLabel lblEmail = new JLabel("E-mail");
lblEmail.setBounds(10, 214, 46, 14);
panel.add(lblEmail);
JRadioButton rdbtnM_2 = new JRadioButton("M");
rdbtnM_2.setBounds(74, 133, 109, 23);
panel.add(rdbtnM_2);
JRadioButton rdbtnF = new JRadioButton("F");
rdbtnF.setBounds(74, 107, 109, 23);
panel.add(rdbtnF);
}
}
Basically I'm expecting to view the frame from the PersonalInfo method when I press the btnPersonalInfo button and right now I only get an empty frame.
Thank you and sorry if this is a duplicate, but it's my first question here.
Remove frame = new JFrame(); from your initialize()
Simply:
JPanel panel = new JPanel();
add(panel, BorderLayout.CENTER);//It will be added to the ContentPane by default.
panel.setLayout(null);
...
Then when calling, remove the following block:
JFrame PersonalInfo = new JFrame("Personal Info");
PersonalInfo content = new PersonalInfo();
PersonalInfo.setContentPane(content);
Replace it by:
PersonalInfo personalInfo = new PersonalInfo();
personalInfo.setSize(700,700);
personalInfo.setLocation(100,15);
....
So this should be your method call:
public void actionPerformed(ActionEvent e) {
PersonalInfo personalInfo = new PersonalInfo();
personalInfo.setSize(700,700);
personalInfo.setLocation(100,15);
personalInfo.setDefaultCloseOperation( JFrame.HIDE_ON_CLOSE );
personalInfo.setResizable(false);
personalInfo.setVisible(true);
}
And this should be your Class:
public class PersonalInfo extends JFrame
{
public PersonalInfo() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
JPanel panel = new JPanel();
add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblPersonalInfo = new JLabel("Personal Information");
lblPersonalInfo.setFont(new Font("Arial", Font.BOLD, 16));
lblPersonalInfo.setBounds(110, 11, 185, 14);
panel.add(lblPersonalInfo);
JLabel lblFullName = new JLabel("Full Name");
lblFullName.setBounds(10, 36, 58, 14);
panel.add(lblFullName);
JLabel lblNationality = new JLabel("Nationality");
lblNationality.setBounds(10, 61, 78, 14);
panel.add(lblNationality);
JLabel lblDateBirth = new JLabel("Date of Birth");
lblDateBirth.setBounds(10, 86, 78, 14);
panel.add(lblDateBirth);
JLabel lblGender = new JLabel("Gender");
lblGender.setBounds(10, 111, 46, 14);
panel.add(lblGender);
JLabel lblAddress = new JLabel("Address");
lblAddress.setBounds(10, 164, 58, 14);
panel.add(lblAddress);
JLabel lblMobile = new JLabel("Mobile");
lblMobile.setBounds(10, 189, 46, 14);
panel.add(lblMobile);
JLabel lblEmail = new JLabel("E-mail");
lblEmail.setBounds(10, 214, 46, 14);
panel.add(lblEmail);
JRadioButton rdbtnM_2 = new JRadioButton("M");
rdbtnM_2.setBounds(74, 133, 109, 23);
panel.add(rdbtnM_2);
JRadioButton rdbtnF = new JRadioButton("F");
rdbtnF.setBounds(74, 107, 109, 23);
panel.add(rdbtnF);
}
}
Hi I am a newbie java programmer, I am currently creating a java gui application using WindowBuilder within eclipse.
I have the layout that I like however, the source code is all in one class, and I can't seem to navigate through the panels correctly.
A link to the image for how the layout of panels is in WindowBuilder - http://postimg.org/image/xmnm9ilm1/
I was wondering how can I best layout the code, and how best to navigate through the program.
Bear in mind I don't know many techical terms.
Also what is the best way to implement a microsoft access backend database that can be editied within the program for login usernames, passwords and adding and removing items? I have a seperate database class at the moment.
Thank You
Source code of program is shown below
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Color;
import javax.swing.JList;
import javax.swing.Box;
import java.awt.Panel;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class UnivEPOS {
private JFrame frmUniveposV;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UnivEPOS window = new UnivEPOS();
window.frmUniveposV.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public UnivEPOS() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmUniveposV = new JFrame();
frmUniveposV.setTitle("UnivEPOS v1.0");
frmUniveposV.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frmUniveposV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmUniveposV.getContentPane().setLayout(new CardLayout(0, 0));
JPanel Login = new JPanel();
Login.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Login, "name_244778779455709");
Login.setLayout(null);
JLabel lblLogin = new JLabel("LOGIN");
lblLogin.setForeground(new Color(255, 255, 255));
lblLogin.setFont(new Font("Tahoma", Font.BOLD, 18));
lblLogin.setBounds(10, 0, 60, 50);
Login.add(lblLogin);
textField = new JTextField();
textField.setBounds(518, 282, 262, 20);
Login.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(518, 319, 262, 20);
Login.add(textField_1);
JLabel lblNewLabel = new JLabel("Username");
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
lblNewLabel.setBounds(416, 283, 92, 14);
Login.add(lblNewLabel);
JLabel lblPassword = new JLabel("Password");
lblPassword.setForeground(new Color(255, 255, 255));
lblPassword.setFont(new Font("Tahoma", Font.BOLD, 16));
lblPassword.setBounds(416, 320, 92, 14);
Login.add(lblPassword);
JButton btnNewButton = new JButton("ENTER");
btnNewButton.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
}
});
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton.setBounds(691, 396, 89, 23);
Login.add(btnNewButton);
JButton btnNewButton_1 = new JButton("EXIT");
btnNewButton_1.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent e) {
}
});
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_1.setBounds(518, 396, 89, 23);
Login.add(btnNewButton_1);
JPanel Home = new JPanel();
Home.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Home, "name_244789265918213");
Home.setLayout(null);
JLabel lblCurrentOrders = new JLabel("CURRENT ORDERS");
lblCurrentOrders.setForeground(new Color(255, 255, 255));
lblCurrentOrders.setBounds(535, 0, 346, 31);
lblCurrentOrders.setFont(new Font("Tahoma", Font.BOLD, 35));
Home.add(lblCurrentOrders);
JButton btnNewButton_2 = new JButton("Previous");
btnNewButton_2.setBounds(614, 598, 95, 31);
Home.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("Next");
btnNewButton_3.setBounds(731, 598, 95, 31);
Home.add(btnNewButton_3);
JButton btnNewButton_6 = new JButton("NEW ORDER");
btnNewButton_6.setBounds(10, 598, 244, 112);
btnNewButton_6.setFont(new Font("Tahoma", Font.BOLD, 18));
Home.add(btnNewButton_6);
JButton btnNewButton_4 = new JButton("Show Paid");
btnNewButton_4.setBounds(614, 632, 95, 31);
Home.add(btnNewButton_4);
JButton btnNewButton_5 = new JButton("Show Unpaid");
btnNewButton_5.setBounds(731, 632, 95, 31);
Home.add(btnNewButton_5);
JButton btnShowAll = new JButton("SHOW ALL");
btnShowAll.setBounds(658, 663, 131, 31);
Home.add(btnShowAll);
JButton btnAdmin = new JButton("ADMIN");
btnAdmin.setBounds(1245, 682, 95, 37);
Home.add(btnAdmin);
JLabel lblCurrentUser = new JLabel("Current User:");
lblCurrentUser.setForeground(new Color(255, 255, 255));
lblCurrentUser.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblCurrentUser.setBounds(1081, 12, 83, 14);
Home.add(lblCurrentUser);
JLabel lblNewLabel_1 = new JLabel("Date & Time:");
lblNewLabel_1.setForeground(new Color(255, 255, 255));
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(10, 14, 80, 14);
Home.add(lblNewLabel_1);
JPanel Order = new JPanel();
Order.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Order, "name_244796279334447");
Order.setLayout(null);
JLabel lblOrder = new JLabel("ORDER:");
lblOrder.setForeground(new Color(255, 255, 255));
lblOrder.setFont(new Font("Tahoma", Font.BOLD, 40));
lblOrder.setBounds(10, 11, 166, 43);
Order.add(lblOrder);
JLabel lblDateTime = new JLabel("DATE & TIME:");
lblDateTime.setForeground(new Color(255, 255, 255));
lblDateTime.setFont(new Font("Tahoma", Font.BOLD, 40));
lblDateTime.setBounds(771, 11, 282, 43);
Order.add(lblDateTime);
JLabel lblTable = new JLabel("TABLE:");
lblTable.setForeground(new Color(255, 255, 255));
lblTable.setFont(new Font("Tahoma", Font.BOLD, 40));
lblTable.setBounds(391, 11, 146, 43);
Order.add(lblTable);
Panel panel = new Panel();
panel.setBounds(10, 75, 650, 489);
Order.add(panel);
panel.setLayout(null);
JLabel lblNewLabel_2 = new JLabel("TOTAL:");
lblNewLabel_2.setForeground(new Color(255, 255, 255));
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 40));
lblNewLabel_2.setBounds(10, 421, 157, 57);
panel.add(lblNewLabel_2);
JLabel lblCurrentOrder = new JLabel("CURRENT ORDER");
lblCurrentOrder.setForeground(new Color(255, 255, 255));
lblCurrentOrder.setBounds(251, 5, 198, 31);
lblCurrentOrder.setFont(new Font("Tahoma", Font.PLAIN, 25));
panel.add(lblCurrentOrder);
Panel panel_1 = new Panel();
panel_1.setBounds(690, 75, 650, 489);
Order.add(panel_1);
panel_1.setLayout(null);
JLabel lblCategories = new JLabel("CATEGORIES");
lblCategories.setForeground(new Color(255, 255, 255));
lblCategories.setFont(new Font("Tahoma", Font.PLAIN, 25));
lblCategories.setBounds(254, 11, 153, 31);
panel_1.add(lblCategories);
JButton btnPrevious = new JButton("PREVIOUS");
btnPrevious.setBounds(462, 455, 89, 23);
panel_1.add(btnPrevious);
JButton btnNext = new JButton("NEXT");
btnNext.setBounds(551, 455, 89, 23);
panel_1.add(btnNext);
JButton btnNewButton_7 = new JButton("SAVE");
btnNewButton_7.setFont(new Font("Tahoma", Font.BOLD, 30));
btnNewButton_7.setBounds(10, 582, 254, 137);
Order.add(btnNewButton_7);
JButton btnSavePay = new JButton("SAVE & PAY");
btnSavePay.setFont(new Font("Tahoma", Font.BOLD, 30));
btnSavePay.setBounds(274, 582, 274, 137);
Order.add(btnSavePay);
JButton btnFinish = new JButton("FINISH");
btnFinish.setFont(new Font("Tahoma", Font.BOLD, 30));
btnFinish.setBounds(558, 582, 253, 137);
Order.add(btnFinish);
JButton button = new JButton("ADMIN");
button.setFont(new Font("Tahoma", Font.BOLD, 11));
button.setBounds(1245, 682, 95, 37);
Order.add(button);
JButton btnExit = new JButton("EXIT");
btnExit.setFont(new Font("Tahoma", Font.BOLD, 11));
btnExit.setBounds(1114, 682, 95, 37);
Order.add(btnExit);
JPanel Reports = new JPanel();
Reports.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Reports, "name_244798869260892");
Reports.setLayout(null);
Panel panel_2 = new Panel();
panel_2.setBounds(0, 180, 1350, 459);
Reports.add(panel_2);
panel_2.setLayout(null);
JLabel lblSales = new JLabel("SALES");
lblSales.setForeground(new Color(255, 255, 255));
lblSales.setFont(new Font("Tahoma", Font.PLAIN, 25));
lblSales.setBounds(600, 0, 78, 52);
panel_2.add(lblSales);
JLabel lblReports = new JLabel("REPORTS");
lblReports.setForeground(new Color(255, 255, 255));
lblReports.setFont(new Font("Tahoma", Font.BOLD, 35));
lblReports.setBounds(556, 0, 174, 52);
Reports.add(lblReports);
JButton btnNewButton_8 = new JButton("SALES");
btnNewButton_8.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnNewButton_8.setBounds(10, 97, 174, 77);
Reports.add(btnNewButton_8);
JButton btnCancellations = new JButton("CANCELLATIONS");
btnCancellations.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnCancellations.setBounds(194, 97, 221, 77);
Reports.add(btnCancellations);
JButton btnItemsSold = new JButton("ITEMS SOLD");
btnItemsSold.setFont(new Font("Tahoma", Font.PLAIN, 25));
btnItemsSold.setBounds(425, 97, 221, 77);
Reports.add(btnItemsSold);
JLabel lblNewLabel_3 = new JLabel("PAGE");
lblNewLabel_3.setForeground(new Color(255, 255, 255));
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 40));
lblNewLabel_3.setBounds(610, 645, 106, 74);
Reports.add(lblNewLabel_3);
JButton btnNewButton_9 = new JButton("PREVIOUS");
btnNewButton_9.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_9.setBounds(860, 645, 163, 74);
Reports.add(btnNewButton_9);
JButton btnNext_1 = new JButton("NEXT");
btnNext_1.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNext_1.setBounds(1025, 645, 164, 74);
Reports.add(btnNext_1);
JButton btnNewButton_10 = new JButton("EXIT");
btnNewButton_10.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_10.setBounds(1199, 645, 141, 74);
Reports.add(btnNewButton_10);
JPanel Settings = new JPanel();
Settings.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Settings, "name_244813941995636");
Settings.setLayout(null);
JLabel lblNewLabel_4 = new JLabel("SYSTEM SETTINGS");
lblNewLabel_4.setForeground(new Color(255, 255, 255));
lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 35));
lblNewLabel_4.setBounds(500, 0, 339, 54);
Settings.add(lblNewLabel_4);
JList list = new JList();
list.setForeground(new Color(255, 255, 255));
list.setBackground(new Color(128, 0, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setFont(new Font("Tahoma", Font.PLAIN, 40));
list.setModel(new AbstractListModel() {
String[] values = new String[] {"USER 1", "USER 2", "USER 3", "USER 4", "USER 5"};
public int getSize() {
return values.length;
}
public Object getElementAt(int index) {
return values[index];
}
});
list.setBounds(10, 82, 634, 481);
Settings.add(list);
JButton btnNewButton_11 = new JButton("ADD USER");
btnNewButton_11.setFont(new Font("Tahoma", Font.BOLD, 11));
btnNewButton_11.setBounds(10, 617, 196, 102);
Settings.add(btnNewButton_11);
JButton btnChangeSuperuserPassword = new JButton("CHANGE SUPERUSER PASSWORD");
btnChangeSuperuserPassword.setFont(new Font("Tahoma", Font.BOLD, 11));
btnChangeSuperuserPassword.setBounds(433, 617, 211, 102);
Settings.add(btnChangeSuperuserPassword);
JButton button_1 = new JButton("EXIT");
button_1.setFont(new Font("Tahoma", Font.BOLD, 11));
button_1.setBounds(1245, 682, 95, 37);
Settings.add(button_1);
Panel panel_3 = new Panel();
panel_3.setBounds(650, 84, 690, 479);
Settings.add(panel_3);
panel_3.setLayout(null);
JLabel lblNewLabel_5 = new JLabel("RECEIPT OF SALE");
lblNewLabel_5.setForeground(new Color(255, 255, 255));
lblNewLabel_5.setFont(new Font("Tahoma", Font.PLAIN, 20));
lblNewLabel_5.setBounds(260, 11, 178, 44);
panel_3.add(lblNewLabel_5);
JLabel lblNewLabel_6 = new JLabel("COMPANY");
lblNewLabel_6.setForeground(new Color(255, 255, 255));
lblNewLabel_6.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblNewLabel_6.setBounds(24, 136, 125, 44);
panel_3.add(lblNewLabel_6);
JLabel lblSalesRepresentative = new JLabel("SALES REP");
lblSalesRepresentative.setForeground(new Color(255, 255, 255));
lblSalesRepresentative.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblSalesRepresentative.setBounds(24, 213, 125, 44);
panel_3.add(lblSalesRepresentative);
JLabel lblAddress = new JLabel("ADDRESS");
lblAddress.setForeground(new Color(255, 255, 255));
lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblAddress.setBounds(24, 171, 125, 48);
panel_3.add(lblAddress);
JLabel lblMessage = new JLabel("MESSAGE");
lblMessage.setForeground(new Color(255, 255, 255));
lblMessage.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblMessage.setBounds(24, 256, 125, 38);
panel_3.add(lblMessage);
textField_2 = new JTextField();
textField_2.setBounds(154, 151, 404, 26);
panel_3.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setColumns(10);
textField_3.setBounds(154, 188, 404, 26);
panel_3.add(textField_3);
textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(154, 228, 404, 26);
panel_3.add(textField_4);
textField_5 = new JTextField();
textField_5.setColumns(10);
textField_5.setBounds(154, 268, 404, 26);
panel_3.add(textField_5);
JPanel Administration = new JPanel();
Administration.setBackground(new Color(128, 0, 0));
frmUniveposV.getContentPane().add(Administration, "name_244816080502214");
Administration.setLayout(null);
JLabel lblNewLabel_7 = new JLabel("ADMINISTRATION");
lblNewLabel_7.setForeground(new Color(255, 255, 255));
lblNewLabel_7.setFont(new Font("Tahoma", Font.BOLD, 35));
lblNewLabel_7.setBounds(506, 0, 335, 43);
Administration.add(lblNewLabel_7);
JLabel lblCategories_1 = new JLabel("CATEGORIES");
lblCategories_1.setForeground(new Color(255, 255, 255));
lblCategories_1.setFont(new Font("Tahoma", Font.PLAIN, 35));
lblCategories_1.setBounds(90, 88, 214, 43);
Administration.add(lblCategories_1);
JLabel lblSubcategories = new JLabel("SUB-CATEGORIES");
lblSubcategories.setForeground(new Color(255, 255, 255));
lblSubcategories.setFont(new Font("Tahoma", Font.PLAIN, 35));
lblSubcategories.setBounds(528, 88, 292, 43);
Administration.add(lblSubcategories);
JLabel label = new JLabel("SUB-CATEGORIES");
label.setForeground(new Color(255, 255, 255));
label.setFont(new Font("Tahoma", Font.PLAIN, 35));
label.setBounds(1008, 88, 292, 43);
Administration.add(label);
JList list_1 = new JList();
list_1.setBounds(55, 142, 292, 404);
Administration.add(list_1);
JList list_2 = new JList();
list_2.setBounds(528, 142, 292, 404);
Administration.add(list_2);
JList list_3 = new JList();
list_3.setBounds(1008, 142, 292, 404);
Administration.add(list_3);
JButton btnAdd = new JButton("ADD");
btnAdd.setBounds(55, 557, 89, 23);
Administration.add(btnAdd);
JButton button_2 = new JButton("ADD");
button_2.setBounds(528, 557, 89, 23);
Administration.add(button_2);
JButton button_3 = new JButton("ADD");
button_3.setBounds(1008, 557, 89, 23);
Administration.add(button_3);
JButton btnRemove = new JButton("REMOVE");
btnRemove.setBounds(258, 557, 89, 23);
Administration.add(btnRemove);
JButton button_4 = new JButton("REMOVE");
button_4.setBounds(731, 557, 89, 23);
Administration.add(button_4);
JButton button_5 = new JButton("REMOVE");
button_5.setBounds(1211, 557, 89, 23);
Administration.add(button_5);
JButton btnReports = new JButton("REPORTS");
btnReports.setFont(new Font("Tahoma", Font.BOLD, 30));
btnReports.setBounds(10, 638, 180, 81);
Administration.add(btnReports);
JButton btnSettings = new JButton("SETTINGS");
btnSettings.setFont(new Font("Tahoma", Font.BOLD, 30));
btnSettings.setBounds(200, 638, 185, 81);
Administration.add(btnSettings);
JButton button_6 = new JButton("EXIT");
button_6.setFont(new Font("Tahoma", Font.BOLD, 11));
button_6.setBounds(1245, 682, 95, 37);
Administration.add(button_6);
}
}
Source code of database class is shown below
import java.awt.event.*;
import java.sql.*;
public class database {
Connection con;
Statement st;
ResultSet rs;
public database()
{
connect();
frame();
}
public void connect()
{
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:db";
con = DriverManager.getConnection(db);
st = con.createStatement();
}
catch(Exception ex){
}
}
public void frame()
{
new UnivEPOS();
}
}