Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Using JPanels (Can't seem to find any help for this. )
Using JPanels [message #1031979] Tue, 02 April 2013 12:37
Calum Mackie is currently offline Calum MackieFriend
Messages: 1
Registered: April 2013
Junior Member
I currently have 2 classes, in one class is the main program and in the other is a JPanel. What I want to be able to do is at some point during the main program, based on user input, is open the JPanel and use a value from that to lead into an if statement.

I have a few problems, one is that my JPanel doesn't actually show anything at the minute, it just comes up as a tiny window with min/max/close. The biggest problem I'm facing however is how can I actually open the JPanel from the main program? Been searching online for answers but nothing seems to work. Any help would be appreciated.

Here's the code for my JPanel:
(it's incomplete because all I want to do at the minute is make it work before adding all the buttons)
(the idea with the bookval is that when you click the correct one the program proceeds - eg. if book2val == 1 go ahead; else "Fail")

package quest;

import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class BookCase extends JPanel

{
public void main(String[] args)

{

int book1val = 0;
int book2val = 0;
int book3val = 0;
int book4val = 0;
int book5val = 0;
int book6val = 0;
int book7val = 0;
int book8val = 0;
int book9val = 0;
int book10val = 0;

JPanel titlePanel, checkPanel, bookPanel;
JButton redButton, blueButton, greenButton, blackButton,
orangeButton, yellowButton, pinkButton, greyButton, purpleButton;



JPanel totalGUI = new JPanel();
totalGUI.setLayout(null);

titlePanel = new JPanel();
titlePanel.setLayout(null);
titlePanel.setLocation(10, 0);
titlePanel.setSize(250, 30);
totalGUI.add(titlePanel);

bookPanel = new JPanel();
bookPanel.setLayout(null);
bookPanel.setLocation(10, 80);
bookPanel.setSize(260, 70);
totalGUI.add(bookPanel);

redButton = new JButton("Red Book");
redButton.setLocation(0, 0);
redButton.setSize(30, 120);
redButton.addActionListener((ActionListener) this);
bookPanel.add(redButton);

blueButton = new JButton("Blue Book");
blueButton.setLocation(30, 0);
blueButton.setSize(30, 120);
blueButton.addActionListener((ActionListener) this);
bookPanel.add(blueButton);

greenButton = new JButton("Green Book");
greenButton.setLocation(60, 0);
greenButton.setSize(30, 120);
greenButton.addActionListener((ActionListener) this);
bookPanel.add(greenButton);

blackButton = new JButton("Black Book");
blackButton.setLocation(90, 0);
blackButton.setSize(30, 120);
blackButton.addActionListener((ActionListener) this);
bookPanel.add(blackButton);

totalGUI.setOpaque(true);

}

}

I'm relatively new to java so if this is just a simple case of stupidity feel free to point me in the right direction, but I just can't seem to find the solution online.

Thanks.
Previous Topic:Hudson Remote APIS
Next Topic:Extracting child report info from Parent report
Goto Forum:
  


Current Time: Thu Apr 25 00:57:45 GMT 2024

Powered by FUDForum. Page generated in 0.08453 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top