Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Button Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button Problems" Watch "Button Problems" New topic
Author

Button Problems

Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
I am having trouble with my program, I have been compiling it repeatedly and has all work fine until I wrote the class attempting to acess my action listener for the calculation this is when the errors have started. I have remade all my buttons and class several times to make sure datatypes do not conflict but the same errors continue to occure so please exaime my source code and help me debug

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

public class upperTolower extends JFrame
{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

private JLabel upperCaseL, lowerCaseL;
private JTextField upperCaseTF, lowerCaseTF;
private JButton calcUpperB, calcLowerB, exitB;
ExitButtonHandler exitHandler;
CalculateLButtonHandler calculateLHandler;
CalculateUButtonHandler calculateUHandler;

public upperTolower()
{
setTitle("Character Conversion");

upperCaseL = new JLabel("Enter Upper Case Values: ", SwingConstants.CENTER);
lowerCaseL = new JLabel("Enter Lower Case Values: ", SwingConstants.CENTER);

upperCaseTF = new JTextField(15);
lowerCaseTF = new JTextField(15);

calcUpperB = new JButton("Upper");
calculateUHandler = new CalculateUButtonHandler();
calcUpperB.addActionListener(calculateUHandler);

calcLowerB = new JButton("Lower");
calculateLHandler = new CalculateLButtonHandler();
calcLowerB.addActionListener(calculateLHandler);

exitB = new JButton("Exit");
exitHandler = new ExitButtonHandler();
exitB.addActionListener(exitHandler);

Container pane = getContentPane();
pane.setLayout(new GridLayout(3,2));

pane.add(upperCaseL);
pane.add(upperCaseTF);
pane.add(lowerCaseL);
pane.add(lowerCaseTF);
pane.add(calcUpperB);
pane.add(calcLowerB);
pane.add(exitB);

setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}



public class CalculateUButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char LowerCaseValues, UpperCaseValues;

LowerCaseValues = Character.parseChar(lowerCaseTF.getText());

upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));

}
}


public static void main(String[] args)
{
upperTolower upperTolowerObject = new upperTolower();
}
}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Care to share with us the errors you are having?


GenRocket - Experts at Building Test Data
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
Originally posted by Chase Becicka:

public class CalculateUButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char LowerCaseValues, UpperCaseValues;

LowerCaseValues = Character.parseChar(lowerCaseTF.getText());

upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));

}
}




This doesn't look like it would compile. I can't find a parseChar method for Character under java1.4.2. Are you trying to just switch the case of all the chars?

You don't need the "" either. The +LowerCaseValues doesn't make sense.

Just some background hints, you might want to ensure all your class names start with a capital letter. Also, variable names might be better off starting with a lowercase letter. Other programmers will be accustomed to using the case of the first letter to differentiate between classes, vars, and method names.

HTH,
Aaron R>
Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
C:\Documents and Settings\diadem\Desktop\upperTolower.java:14: cannot resolve symbol
symbol : class ExitButtonHandler
location: class upperTolower
ExitButtonHandler exitHandler;
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:15: cannot resolve symbol
symbol : class CalculateLButtonHandler
location: class upperTolower
CalculateLButtonHandler calculateLHandler;
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:33: cannot resolve symbol
symbol : class CalculateLButtonHandler
location: class upperTolower
calculateLHandler = new CalculateLButtonHandler();
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:37: cannot resolve symbol
symbol : class ExitButtonHandler
location: class upperTolower
exitHandler = new ExitButtonHandler();
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:64: cannot resolve symbol
symbol : method parseChar (java.lang.String)
location: class java.lang.Character
LowerCaseValues = Character.parseChar(lowerCaseTF.getText());
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:66: toUpperCase(char) in java.lang.Character cannot be applied to (int)
upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));


Here are my errors
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

The reason for the 1st 5 errors you listed are probably because these classes that your are trying to make new objects from don't exist. And then you try and use these classes in your code. You might need to check and see if your teacher has these or maybe these are what you are supposed to create for your assignment.
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
This is starting to sound more like a java programming issue than a graphics one.

As Gregg mentioned, you are missing some classes, but it appears you could do a little rewriting and dispense with them. Unless they are required by the course? you are taking.

What did your prgm look like before you got the compile errors?

Regards,
Aaron R>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Button Problems
 
Similar Threads
remove lines in a JtextArea
GridBagLayout Question: Irregular Spacing
why doesn't this code work?
Null pointer exception in button event handler.
need help checking this code