Article View: borland.public.jbuilder.java.language
Article #8275What is going on here ??
From: Asger Joergensen
Date: Thu, 05 Apr 2001 08:08
Date: Thu, 05 Apr 2001 08:08
110 lines
3594 bytes
3594 bytes
Hi there
I know this is a rather large message, but i found it much easyer
to show the code then to explain what i do.
The problem is that the below code doesn work corectly in the
Browsers (using win2k)
In IE 50 it doesn't do nothing it just shows two labels
and two textfields.
In Netscape 4.7 the part where i sort out unwanted characters works,
but the setText doesn't work.
In the AppletViewer every thing works Ok.
What is wrong ????
Thanks in advance
Asger
I love my C++ more and more every day..;-)
Code------------------------
public class Celsius2Fahrenheit extends Applet implements KeyListener
{
TextField edCelsius, edFahrenheit;
Label lbCelsius,lbFahrenheit;
String validChar = "1234567890.";
boolean isValidChar = false;
public void init()
{
int adjust = 8 * Toolkit.getDefaultToolkit().getScreenResolution() /
144;
Font oF = getFont();
Font nF = new Font( oF.getName(), oF.getStyle(), oF.getSize() +
adjust);
setFont(nF);
Color cl = new Color(192,192,192);
setBackground(cl);
lbCelsius = new Label("Celsius:");
add(lbCelsius);
edCelsius = new TextField(10);
edCelsius.addKeyListener(this);
add(edCelsius);
lbFahrenheit = new Label(" Fahrenheit:");
add(lbFahrenheit);
edFahrenheit = new TextField(10);
edFahrenheit.addKeyListener(this);
add(edFahrenheit);
}//End public void init()
public void keyTyped(KeyEvent e) {
char Key = e.getKeyChar();
if(validChar.indexOf((int)Key) == -1 && Key != e.VK_BACK_SPACE){
e.setKeyChar((char)0);
isValidChar = false;
return;
}
isValidChar = true;
}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){
if(isValidChar == false)return;
TextField Src = (TextField)e.getSource();
String Txt = Src.getText();
if(Src == edFahrenheit){
if(Txt.length() == 0){
edCelsius.setText("");
return;
}else{
edCelsius.setText(fahrenheitToCelsius(Txt));
}
}else if(Src == edCelsius){
if(Txt.length() == 0){
edFahrenheit.setText("");
return;
}else{
edFahrenheit.setText(celsiusToFahrenheit(Txt));
}
}
}
String celsiusToFahrenheit(String cStr){
double C = Double.parseDouble(cStr);
C = 9.0 / 5.0 * C + 32;
return Double.toString(C);
}
String fahrenheitToCelsius(String fStr){
DecimalFormat fourDigets = new DecimalFormat("0.0000");
double F = Double.parseDouble(fStr);
F = 5.0 / 9.0 * (F - 32);
return fourDigets.format(F);
}
}//End public class Celsius2Fahrenheit
Technical Details
Message-ID:
<3ACC280A.634712FB@get2net.dk>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,d79e6ea1ea88ea5,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-04-05 01:22:03 PST Message-ID: <3ACC280A.634712FB@get2net.dk> Date: Thu, 05 Apr 2001 10:08:42 +0200 From: Asger Joergensen <Asger.P@get2net.dk> X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: da,en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: What is going on here ?? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 195.47.152.166 X-Trace: dnews 986458319 195.47.152.166 (5 Apr 2001 01:11:59 -0700) Lines: 112 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews