• 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

Help!

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright here is the situation, I am trying to create a Calculator applet that accepts complex number expressions, does the calculation and returns the results in a seperate text area in the form of:

expression = "rectangular form" or "polar form"

also there are three radio buttons which change the format of the expression.

at this point I can only get the calculate button to work half-arsed, and none of the radio buttons to work at all.

here is my CalcApplet.java file

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CalcApplet extends JApplet implements ActionListener
{
protected JTextField entry;
protected JTextArea results;
protected JScrollPane resultsPane;
protected JButton calculate, clear, clearResults;
protected JRadioButton infix, prefix, postfix;
protected JPanel input, output, mode;
protected ButtonGroup group;

static String sInfix = "Infix Notation";
static String sPrefix = "Prefix Notation";
static String sPostfix = "Postfix Notation";

public void init()
{
// create GUI components
entry = new JTextField(35);
results = new JTextArea(10, 40);
JScrollPane resultsPane = new JScrollPane(results);
calculate = new JButton("Calculate");
clear = new JButton("Clear");
clearResults = new JButton("Clear Results");
infix = new JRadioButton(sInfix);
infix.setActionCommand(sInfix);
infix.setSelected(true);
prefix = new JRadioButton(sPrefix);
prefix.setActionCommand(sPrefix);
postfix = new JRadioButton(sPostfix);
postfix.setActionCommand(sPostfix);
group = new ButtonGroup();
group.add(infix);
group.add(prefix);
group.add(postfix);

//create and fill mode JPanel
mode = new JPanel();
mode.add(infix);
mode.add(prefix);
mode.add(postfix);

//create and fill the input JPanel
input = new JPanel();
input.add(entry);
input.add(calculate);
input.add(clear);

//create and fill the output JPanel
output = new JPanel();
output.add(resultsPane);
output.add(clearResults);

//add the JPanels to the content pane
getContentPane().add(mode, BorderLayout.NORTH);
getContentPane().add(input, BorderLayout.CENTER);
getContentPane().add(output, BorderLayout.SOUTH);

//Setup ActionListener
calculate.addActionListener( this );
clear.addActionListener( this );
clearResults.addActionListener( this );
infix.addActionListener ( this );
prefix.addActionListener ( this );
postfix.addActionListener ( this );
}

public Term createTermObject()
{

String text = entry.getText();
Term expr = ExprParser.parse( text );
return expr;
}

public void actionPerformed( ActionEvent e )
{

Object src = e.getSource();

if (src == calculate)
{
Term term = createTermObject();
results.append( term + "=" + term.toString() + " or " /* + term.toPolarString*/ + "\n" );
}
else if (src == clear)
{
entry.setText("");
}
else if (src == clearResults)
{
results.setText("");
}

}
}

and here is the website it is currently on: www.cet.nau.edu/~ckm33/cs126/proj5

and this is the site where the instructor put up what a finished product should look like and do:

http://www.cet.nau.edu/~apr/cs126/src/proj5/index.html

As you can see if you put in 5*i on his version the result is proper,
but when you use mine it comes out wrong...

any ideas?
 
Christopher McLaughlin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one other this is that I have looked up how to implement and use Jradiobuttons through sun's tutorial but it only has an example with changing pictures, and I need it to change the way the result is printed out.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christopher,

Please don't post the same question in multiple forums. It's exremely frustrating when somebody takes the time to help you, and then finds out you've already gotten an answer in a different place. Also, you may get confused when different people start giving different suggestions as to what to try...

i imagine a moderator will close one of these posts soon...

Link to other tread
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, what is your question? Posting a big hunk of code and saying "it doesn't work" makes it hard for anyone to help you. HOW does it not work? What is it specifically doing (or not doing) that you think should be different?

HOW are the radio buttons not working? they show up, only one can be selected at a time... are you saying you want them vertically like the professors?

if you ask simple, focused questions, you're much more likely to get a response.

something else that would help would be to use the "code" tags. if you put [ code ] and [ /code ] (without the spaces) around your code, it will preserve the formatting, making it MUCH easier for everyone else to read.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic