Geoff Vurel

Greenhorn
+ Follow
since Jan 14, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Geoff Vurel

Thanks Rob.

I still have something wrong hopefully you or someone can assist. I don't get the "about" button to show in my frame. I want that button to show and when I click it open frame2.
15 years ago
I have my code compile but somewhere I made a mistake. When I run my app the only thing that shows is the "Launch another frame" window. Can someone help me figure out why?

15 years ago
My code does not compile, sorry I thought I included the errors. We have not covered MigLayout in my class. I have to use BorderLayout, FlowLayout, or Boxlayout in this project. Here are the errors I get when compiling right now.

Project01b.java:33: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
Project01b.java:35: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
Project01b.java:38: cannot find symbol
symbol : method FlowLayout()
location: class Project01b
panel.add(choice, FlowLayout());
^
3 errors
15 years ago
I am looking for some assistance with two questions.
1. How do I make the 'About' button show in the 'bowling prices' window and then 'launch in another frame' frame open when clicking 'About' from the 'Bowling Prices' window.
2. FlowLayout isn't showing all my fields as I need it to. The "Bowler Type" field has data that is not showing.

I don't have to use flowlayout, if another layout would work better please advise.

15 years ago
I got the brace situation figured out. Now onto my other problems. Thanks for the help.
15 years ago
I really struggle with the brace placement. I have made a few corrections, including the one you said, but now get even more errors that are similar leading me to believe I still have brace errors:


Project01b.java:114: illegal start of expression
public class AboutListener implements ActionListener {
^
Project01b.java:124: illegal start of expression
public class MyPanel extends JPanel {
^
Project01b.java:138: illegal start of expression
public void actionPerformed(ActionEvent e) {
^
Project01b.java:138: illegal start of expression
public void actionPerformed(ActionEvent e) {
^
Project01b.java:138: ';' expected
public void actionPerformed(ActionEvent e) {
^
Project01b.java:138: ';' expected
public void actionPerformed(ActionEvent e) {
^
Project01b.java:141: reached end of file while parsing
}
^
7 errors
15 years ago
OK, thanks for the code pasting idea. it is easier to read.

Here is my error message:
Project01b.java:114: illegal start of expression
public class AboutListener implements ActionListener {
^
Project01b.java:141: reached end of file while parsing
}→
^
2 errors

15 years ago
I am working on a project for my java class. I would like some suggestions leading me in the right direction to fixing my problems with the program below. Please do not come right out and tell me the answers, I want to figure it out but need someone to lead me in the right direction.

Here are my requirements, that will help explain what I am doing / trying to do.
1.

Perform at least one meaningful calculation based on values entered by the user.
2.

Use at least two different layout managers.
3.

Provide an attractive blend of colors and fonts.
4.

Use several (three or more) different types of Swing components.
5.

Have inner class listeners for events fired by input components.
6.

Use the Graphics class to draw on one or more components or containers.
7.

Have a pop-up "About" frame that shows your name. This frame must be launched from the main application frame.


Here is what I have. Somewhere something isn't right and I am not sure why or where.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
public class Project01b implements ActionListener {
JFrame frame;
JPanel panel;
JList choice;
JTextField quantity;
JCheckBox league;
JTextArea message;
JFrame frame2;
JButton about;
String[] items = {"Student Bowler", "Adult Bowler", "Senior Bowler"};
double[] prices = {1.50, 2.50, 2.00};
public static void main(String[] args) {
Project01b me = new Project01b();
me.go();
}
public void go() {
frame = new JFrame("Bowling Prices");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(220, 220);
frame.setResizable(false);
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel("Bowler Type"));
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(Color.white);
choice = new JList(items);
choice.setSelectedIndex(0);
choice.addListSelectionListener(new SelectionListener());
panel.add(choice, BorderLayout.WEST);
frame.getContentPane().add(choice);
frame.getContentPane().add(new JLabel("# of games"));
panel.add(choice, BorderLayout.CENTER);
quantity = new JTextField(4);
quantity.addActionListener(new QuantityListener());
panel.add(choice, BorderLayout.EAST);
frame.getContentPane().add(quantity);
league = new JCheckBox("League Bowler");
league.addItemListener(new LeagueListener());
frame.getContentPane().add(league);
message = new JTextArea(3, 15);
message.setBackground(Color.black);
message.setForeground(Color.yellow);
message.setEditable(false);
frame.getContentPane().add(message);
frame.setVisible(true);
frame2 = new JFrame("Launch another frame");
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setSize(300, 200);
about = new JButton("About");
about.addActionListener(new AboutListener());
frame2.getContentPane().add(about);
frame2.setVisible(true);
}
class SelectionListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
if (quantity.getText().length() > 0) {
showOrderSummary();
}
else {
message.setText("");
message.append("\n" + " Please enter a quantity");
}
}
}
class QuantityListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
showOrderSummary();
}
}
class LeagueListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
if (quantity.getText().length() > 0) {
showOrderSummary();
}
else {
message.setText("");
message.append("\n" + " Please enter a quantity");
}
}
}
private void showOrderSummary() {
message.setText("");
try {
int qty = Integer.parseInt(quantity.getText().trim());
if (qty > 0) {
double price = prices[choice.getSelectedIndex()];
double amount = qty * price;
if (league.isSelected()) {
amount *= 0.90;
}
NumberFormat nf = NumberFormat.getCurrencyInstance();
String amountAsString = nf.format(amount);
message.append(qty + " " + (String)choice.getSelectedValue() + "(s)");
if (league.isSelected()) {
message.append("\n" + "With league bowler discount");
}
else {
message.append("\n" + "No discount");
}
message.append("\n" + "Total amount due: " + amountAsString);
}
else {
message.append("\n" + " Quantity must be positive");
}
}
catch (NumberFormatException err) {
message.append("\n" + " Quantity must be numeric");
}
public class AboutListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFrame popUp = new JFrame("About frame");
popUp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
popUp.setSize(250,200);
MyPanel panel = new MyPanel();
popUp.getContentPane().add(panel);
popUp.setVisible(true);
}
public class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
int width = this.getWidth();
int height = this.getHeight();
Image bowling = new ImageIcon("Bowling.jpg").getImage();
g.drawImage(bowling,0,0,this);
g.setFont(new Font("SansSerif", Font.BOLD, 12));
g.setColor(Color.green);
g.drawString("Go Bowling", 160, 165);g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.red);
g.drawString("Jeff Burel", width/4, height/2);
}
public void actionPerformed(ActionEvent e) {
((JButton)e.getSource()).setVisible(false);
}
}
}
}
15 years ago
I have to create a program that includes several of the topics I have learned so far in my class. My program has to include:
Perform at least one meaningful calculation based on values entered by the user.
Use at least two different layout managers.
Provide an attractive blend of colors and fonts.
Use several (three or more) different types of Swing components.
Have inner class listeners for events fired by input components.
Use the Graphics class to draw on one or more components or containers.

I know how to do each of these individually. My question is how do I combine them into one program? Can I take what I have for each one and then list them one after another? Or do I need to somehow combine them together?
15 years ago
forget this question
15 years ago
Newbie.java:5: illegal start of expression
for (int i = 0; i< x.length; i+) {
^
Newbie.java:5: not a statement
for (int i = 0; i< x.length; i+) {
^
2 errors
15 years ago
New to java trying to use try catch finally. With try I am looking to make sure the string length is more than 1 character. I have something wrong but not sure what it is. Please assist.





[HENRY: Added Code Tags]
15 years ago