aspose file tools*
The moose likes Cattle Drive 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "A confused new user of Java that needs some help" Watch "A confused new user of Java that needs some help" New topic
Author

A confused new user of Java that needs some help

John Charney
Greenhorn

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) {
super(title);
JTabbedPane tabPane = new JTabbedPane();
Container c = getContentPane();
c.add(tabPane, "Center");
SelectName name = new SelectName();
tabPane.addTab("Name",name);
SelectOrder order = new SelectOrder();
tabPane.addTab("Order",order);
tabPane.setSelectedIndex(0);
addWindowListener(new CloseWindow());
}
public static void main(String [] args) {
Tabs t = new Tabs("Tab display");
t.pack();
t.show();
}
class CloseWindow extends WindowAdapter {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
}
class SelectName extends JPanel {
private DrawOn canvas = new DrawOn();
private JComboBox color = new JComboBox();
private Color [] theColor = {Color.red,Color.green,Color.blue};
private String [] colorName = {"Red","Green","Blue"};

public SelectName() {
setLayout(new FlowLayout());
add(color);
add(canvas);
for (int i=0; i<colorName.length; i++) >
color.addItem(colorName);
canvas.setPreferredSize(new Dimension(150,150));
color.addItemListener(canvas);
}
class DrawOn extends JPanel implements ItemListener {
public void itemStateChanged(ItemEvent event) {
Object source = event.getItem();
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(theColor[color.getSelectedIndex()]);
}
}
}
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.black,Color.blue,Color.cyan,Color.darkGray,
Color.gray,Color.green,Color.lightGray,Color.magenta,Color.orange,
Color.pink,Color.red,Color.white,Color.yellow};
private String message = "Hi there";
public SelectOrder() {
setLayout(new FlowLayout());
add(color);
add(italic);
add(bold);
add(canvas);
names.setSelectedIndex(0);
names.addListSelectionListener(canvas);
canvas.setPreferredSize(new Dimension(150,150));
italic.addItemListener(canvas);
bold.addItemListener(canvas);
}
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;
else
style -= Font.ITALIC;
if (source == bold)
if (change == ItemEvent.SELECTED)
style += Font.BOLD;
else
style -= Font.BOLD;
repaint();
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false)
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setFont(new Font("Serif",style,24));
g.setColor(theColor[names.getSelectedIndex()]);
g.drawString(message, 50,50);
}
}
}
}
Johannes de Jong
tumbleweed
Bartender

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A confused new user of Java that needs some help
 
Similar Threads
A Question on JTabbedPanes
A confused new user of Java that needs some help
Help i need help with borderlayout
change Border color of JTAbbedPane and selection of TabbedPane..Plz solve Problem
Getting a couple errors on scribble applet