federico elbl

Greenhorn
+ Follow
since Oct 14, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by federico elbl

I'm trying to run this program both as an applet and an application, but I'm getting the following error when I try to compile it:

How can I fix this? Below is the code for my program.
-Maria
21 years ago
I worked a bit more on my program, but I'm having trouble making the scientific buttons work. Could you guys help me with those actions?
Below is the code for the program.
Thanks a lot.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class calculator extends JApplet implements ActionListener{
private JButton[] buttons;
private String[] ops = {"CE", "/", "*", "-", ".", "+", "MEM", "MRC",
"SIN", "TAN", "ASIN", "COS","ATAN","X","SQRT","EXP","PI",
"%", "="};
private JLabel output, blank;
private Container contentP;
private String operation;
private double number1, number2, result;
private boolean cleared = false;

public void init(){
contentP = getContentPane();
JPanel container = new JPanel();
container.setLayout(new FlowLayout(FlowLayout.CENTER));
output = new JLabel("");
output.setBorder(new MatteBorder(2, 2, 2, 2, Color.gray));
output.setPreferredSize(new Dimension(1, 26));
contentP.setBackground(Color.white);
contentP.add("North", output);
contentP.add("Center", container);

blank = new JLabel(" ");
container.add(blank);

buttons = new JButton[29];
for (int i = 0; i < 10; ++i){
buttons[i] = new JButton((new Integer(i)).toString());
}
for (int i = 10; i < buttons.length; ++i){
buttons[i] = new JButton(ops[i - 10]);
}
for (int i = 0; i < buttons.length; ++i){
buttons[i].addActionListener(this);
}
JButton[] alignButtons = new JButton[29];
alignButtons[0] = buttons[10]; // CE
alignButtons[4] = buttons[11]; // /
alignButtons[8] = buttons[12]; // *
alignButtons[12] = buttons[13]; // -
alignButtons[1] = buttons[7]; // 7
alignButtons[2] = buttons[8]; // 8
alignButtons[3] = buttons[9]; // 9
alignButtons[5] = buttons[4]; // 4
alignButtons[6] = buttons[5]; // 5
alignButtons[7] = buttons[6]; // 6
alignButtons[9] = buttons[1]; // 1
alignButtons[10] = buttons[2]; // 2
alignButtons[11] = buttons[3]; // 3
alignButtons[13] = buttons[0]; // 0
for (int i = 14; i < buttons.length; ++i){
alignButtons[i] = buttons[i];
} addButtons(alignButtons, container);
} // init()
void addButtons(JButton[] btns, Container cont){
for (int i = 0; i < btns.length; ++i){
cont.add(btns[i]);
}
}
public static void main(String args[]){
JFrame applicationWindow = new JFrame("calculator");
applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calculator appletObject = new calculator();
applicationWindow.getContentPane().add(appletObject, BorderLayout.CENTER);
applicationWindow.setBounds(0,0, 500, 200);
applicationWindow.setVisible(true);
appletObject.init();
appletObject.start();
} // main()
public void actionPerformed(ActionEvent ae){
JButton but = (JButton)ae.getSource();
String op = but.getText();

if (op.equals(".")){
String temp = output.getText();
if(temp.indexOf('.') == -1){
output.setText(output.getText() + op);
}
}
else if(op.equals("CE")){
output.setText("");
operation = "";
number1 = 0.0;
number2 = 0.0;
}
else if("+-*/".indexOf(op) != -1){
operation = op;
try{
number1 = Double.parseDouble(output.getText());
}
catch(Exception e){
e.printStackTrace();
number1 = 0.0;
}
finally{
cleared = true;
}
}
else if(op.equals("=")){
try{
number2 = Double.parseDouble(output.getText());
}
catch(Exception e){
e.printStackTrace();
number2 = 0.0;
}
if(operation.equals("+")){
result = number1 + number2;
}
else if(operation.equals("-")){
result = number1 - number2;
}
else if(operation.equals("*")){
result = number1 * number2;
}
else if(operation.equals("/")){
result = number1 / number2;
}
output.setText(String.valueOf(result));
cleared = true;
operation = "";
}
else{
if(cleared == true){
output.setText("");
cleared = false;
}
output.setText(output.getText() + but.getText());
}
}
}
21 years ago
Hi everybody,
I'm trying to make this calculator program work as an applet AND as an application. I tried using:

in many different ways, but it didn't work. Can sombody help me make it work?
Below is the source code for my calculator program.
Thanks in advance,
-Fede
ps-You can also e-mail me at [email protected]
21 years ago
thanks a lot carl! i made that work, but now the jtextarea is not working. is giving me this error:

/tmp/26198/CircleTest.java:48: cannot resolve symbol
symbol : method showMessageDialog (,javax.swing.JTextArea,int)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog( null, output, JOptionPane.INFORMATION_MESSAGE );
^
1 error
and this is the code i have:
21 years ago
Thanks a lot. Now is giving me these three errors:

21 years ago
Thanks a lot. Now is giving me these three errors:

21 years ago
Thanks a lot. Now is giving me these three errors:

21 years ago
Hi, I'm new with Java, and I need help with a program that I wrote.
It needs to prompt the user for the x value, the y value, and the radius value, and then display the info in a JTextArea. Is giving me the following error:

I don't know what I'm doing wrong. I would really appreciate your help with this. This is the code i have:

Thank you so much.
21 years ago
Hi, I'm new with Java, and I need help with a program that I wrote.
It needs to prompt the user for the x value, the y value, and the radius value, and then display the info in a JTextArea. Is giving me the following error:

I don't know what I'm doing wrong. I would really appreciate your help with this. This is the code i have:

Thank you so much.
21 years ago
Hi, I'm new with Java, and I need help with a program that I wrote.
It needs to prompt the user for the x value, the y value, and the radius value, and then display the info in a JTextArea. Is giving me the following error:

I don't know what I'm doing wrong. I would really appreciate your help with this. This is the code i have:

Thank you so much.
21 years ago
Hi, I'm new with Java, and I need help with a program that I wrote.
It needs to prompt the user for the x value, the y value, and the radius value, and then display the info in a JTextArea. Is giving me the following error:

I don't know what I'm doing wrong. I would really appreciate your help with this. This is the code i have:

Thanks a lot
21 years ago
could somebody give me a detailed explanation of how this tictactoe game program works?
thanks you. this is the code:
import javax.swing.*;
import java.awt.*;
import java.applet.*;
public class TicTac extends JApplet
{
public void init()
{
// declaration aand created array
int Array[] = new int[8];
String input1;
String input2;
int choice1 = 0;
int choice2;
for(int i=0; i < Array.length; i++) Array = 0;
while (choice1 == 0)
{
input1 = JOptionPane.showInputDialog
("Please select your symbol\n"+
"1= O \n"+
"2= X \n");
if (input1.equals("1")) choice1 = 1;
if (input1.equals("2")) choice1 = 2;
}
//converts string to integer
//choice1 = Integer.parseInt( input1 );
}
// draws the TicTacToe Board...
public void paint(Graphics g)
{
Dimension d = getSize();
g.setColor(Color.blue);
int sz = 0;
if (d.height/4 - 10 < d.width/4) sz = d.height / 4;
elsesz = d.width / 4;
for (int j=0; j < 4; j++)
{
g.drawLine(10,sz*j+10,sz*3+10,sz*j+10);
g.drawLine(j*sz+10,10,j*sz+10,sz*3+10);
}
g.setColor(Color.black);
g.drawRect(9,9,sz*3+2,sz*3+2);
} //end of paitn method
}// end of class
21 years ago
Hi, I'm new with Java, and I need help with an assigment about copying arrays, I was wondering if anyone could help me out.
I need to design a program that asks user to enter name and then displays it dysplaying the index and value, like:

I would really appreciate your help. You can reply here or e-mail me at [email protected]
Thanks in advance,
Federico
[ October 14, 2003: Message edited by: federico elbl ]
21 years ago