Blog Tools
Edit your Blog
Build a Blog
View Profile
« July 2009 »
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
You are not logged in. Log in
Entries by Topic
All topics  «
Java help
Thursday, 25 November 2004

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

public class Exam2prog extends JApplet {

int cel, fah, grabInput;
double math;
JLabel fLabel=new JLabel("Fahrenheight: ");
JLabel cLabel=new JLabel("Celcius: ");
JTextField fField=new JTextField(4);
JTextField cField=new JTextField(4);
private Container container;
private FlowLayout layout;


public void init() {

try{

Panel p=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();

p.add(fLabel);
p2.add(fField);
p3.add(cLabel);
p4.add(cField);

TextFieldHandler handler=new TextFieldHandler();
fField.addActionListener(handler);
cField.addActionListener(handler);

layout=new FlowLayout();
container=getContentPane();
container.setLayout(layout);
container.add(p);
container.add(p2);
container.add(p3);
container.add(p4);
}
catch(Exception exception) {
JOptionPane.showMessageDialog(this,""+exception.getMessage());
}


}

public class TextFieldHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {




if(event.getSource()==fField) {
grabInput=Integer.parseInt(fField.getText());
math=((9.0/5.0)*grabInput+32);
cField.setText(""+math);
showStatus("Fahrenheight to Celcius");
}
else if(event.getSource()==cField) {
grabInput=Integer.parseInt(cField.getText());
math=((5.0/9.0)*(grabInput-32));
fField.setText(""+math);
showStatus("Celcius to Fahrenheight");
}
exceptHandling();

}


}
public void exceptHandling() throws Exception {

if(grabInput<=0&&grabInput>=0) {
int errors=0;
}
else {
throw new Exception("You must enter a number.");
}




}




public void paint(Graphics g) {
}
}


Posted by duffman12345 at 8:18 PM EST
Post Comment | Permalink

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

public class Exam2prog extends JApplet {

int cel, fah;
double math;
JLabel fLabel=new JLabel("Fahrenheight: ");
JLabel cLabel=new JLabel("Celcius: ");
JTextField fField=new JTextField(4);
JTextField cField=new JTextField(4);
private Container container;
private FlowLayout layout;


public void init() {

try{

Panel p=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();

p.add(fLabel);
p2.add(fField);
p3.add(cLabel);
p4.add(cField);

TextFieldHandler handler=new TextFieldHandler();
fField.addActionListener(handler);
cField.addActionListener(handler);

layout=new FlowLayout();
container=getContentPane();
container.setLayout(layout);
container.add(p);
container.add(p2);
container.add(p3);
container.add(p4);
}
catch(Exception exception) {
JOptionPane.showMessageDialog(""+exception.getMessage());
}


}

public class TextFieldHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {



int grabInput;
if(event.getSource()==fField) {
grabInput=Integer.parseInt(fField.getText());
math=((9.0/5.0)*grabInput+32);
cField.setText(""+math);
showStatus("Fahrenheight to Celcius");
}
else if(event.getSource()==cField) {
grabInput=Integer.parseInt(cField.getText());
math=((5.0/9.0)*(grabInput-32));
fField.setText(""+math);
showStatus("Celcius to Fahrenheight");
}
exceptHandling(grabInput);

}


}
public void exceptHandling(int input) throws Exception {

if(input<=0&&input>=0) {
int errors=0;
}
else {
throw new Exception("You must enter a number.");
}




}




public void paint(Graphics g) {
}
}


Posted by duffman12345 at 7:34 PM EST
Post Comment | Permalink

Newer | Latest | Older