File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes A confused new user of Java that needs some help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A confused new user of Java that needs some help" Watch "A confused new user of Java that needs some help" New topic

A confused new user of Java that needs some help

John Charney

Joined: Jul 23, 2001
Posts: 3
Hi there I am a fairly new person to the Java language ( I am currently enrolled in a Java programming class this summer at college) anyways I have to create a program that uses a JTabbedPane, providing one tab to input user data such as a name and thier address and another tab that inputs information about a pizza order. My teacher also wants us to be a little bit creative and once the user enters the information and it is visible on the screen we should be able to change the color of that information or make it bold or such. Her si the code that I have been able to come up with so far and when I compile it I have no errors the problem that I am haveing is how do I collect the information from the user and output is so that it is viewable. I am totally lost as to how to do that thanks in advance for any help.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class Tabs extends JFrame {
public Tabs(String title) {
JTabbedPane tabPane = new JTabbedPane();
Container c = getContentPane();
c.add(tabPane, "Center");
SelectName name = new SelectName();
SelectOrder order = new SelectOrder();
addWindowListener(new CloseWindow());
public static void main(String [] args) {
Tabs t = new Tabs("Tab display");
class CloseWindow extends WindowAdapter {
public void windowClosing(WindowEvent event) {
class SelectName extends JPanel {
private DrawOn canvas = new DrawOn();
private JComboBox color = new JComboBox();
private Color [] theColor = {,,};
private String [] colorName = {"Red","Green","Blue"};

public SelectName() {
setLayout(new FlowLayout());
for (int i=0; i<colorName.length; i++) >
canvas.setPreferredSize(new Dimension(150,150));
class DrawOn extends JPanel implements ItemListener {
public void itemStateChanged(ItemEvent event) {
Object source = event.getItem();
public void paintComponent(Graphics g) {
class SelectOrder extends JPanel {
private DrawOn canvas = new DrawOn();
private String [] colorName = {"Black","Blue","Cyan","Dark Gray","Gray",
"Green","Light Gray","Magenta","Orange","Pink","Red","White","Yellow"};
private JList names = new JList(colorName);
private JScrollPane color = new JScrollPane(names);
private JCheckBox italic = new JCheckBox("Italic");
private JCheckBox bold = new JCheckBox("Bold");
private Color [] theColor = {,,Color.cyan,Color.darkGray,
private String message = "Hi there";
public SelectOrder() {
setLayout(new FlowLayout());
canvas.setPreferredSize(new Dimension(150,150));
class DrawOn extends JPanel implements
ItemListener, ListSelectionListener {
int style = Font.PLAIN;
public void itemStateChanged(ItemEvent event) {
Object source = event.getItem();
int change = event.getStateChange();
if (source == italic)
if (change == ItemEvent.SELECTED)
style += Font.ITALIC;
style -= Font.ITALIC;
if (source == bold)
if (change == ItemEvent.SELECTED)
style += Font.BOLD;
style -= Font.BOLD;
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false)
public void paintComponent(Graphics g) {
g.setFont(new Font("Serif",style,24));
g.drawString(message, 50,50);
Johannes de Jong

Joined: Jan 27, 2001
Posts: 5089
John this is not an appropriate post for the "Cattle Drive" forum, so I've moved it to "Swing / JFC / AWT"
Good luck with your question & Java class
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Well John, I have to say that I am surprised that you are already creating GUI's in your JAVA class. Must be an advanced class.
Now, are you wanting to display the resualts of the Pizza Order or the resualts of the color and font schemes they have chosen to change?
If it is the pizza order you want to display, it depends on how you would like it displayed. The way I did something similar is on the last Panel of the JTabbedPane I had a Verify button that displayed a JFrame with the users choices summarized and then a final Submit button as well as a cancel or back button so the user could then edit what they have chosen.
Another way is to add an extra panel and dynamically update the contents to your choices entered on the other panels.
Either way it is really quite simple. But there are different methods for gathering different kinds of data. For instance, your textFields with the name, address, etc, would just require a getText() method upon some event. Checkboxes/radiobuttons are different in the fact that they immedialty send the data somewhere so a temp variable is nice to have.
Anyhow, that's how I did it. I'm sure there are other ways. If you want to talk a little more in depth you can E-mail me at
Sorry for the long message.
Have fun

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: A confused new user of Java that needs some help
jQuery in Action, 3rd edition