• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A confused new user of Java that needs some help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
}
}
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic