The Artima Developer Community
Sponsored Link •

Java Answers Forum
What is the problem in this applet ?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Anas Hammo

Posts: 2
Nickname: anasmohad
Registered: Nov, 2004

What is the problem in this applet ? Posted: Nov 19, 2004 12:20 PM
Reply to this message Reply
Advertisement
import javax.swing.* ;

import java.awt.event.* ;

import java.awt.* ;

import java.text.DecimalFormat ;

public class Ch6_10 extends JApplet implements ActionListener
{

JLabel in , out1 , out2 , out3 , out4 ;

JTextField input , outp1 , outp2 , outp3 , outp4 ;

JButton b ;

public void init ()
{


Container c = getContentPane () ;

c.setLayout ( new FlowLayout () ) ;

in = new JLabel ( " Enter the Double Number " ) ;

c.add ( in ) ;

input = new JTextField ( 5 ) ;

c.add ( input ) ;

out1 = new JLabel ( " Round To Integer " ) ;

c.add ( out1 ) ;

outp1 = new JTextField ( 5 ) ;

outp1.setEditable ( false ) ;

c.add ( outp1 ) ;

out2 = new JLabel ( " Round To Tenths " ) ;

c.add ( out2 ) ;

outp2 = new JTextField ( 5 ) ;

outp2.setEditable ( false ) ;

c.add ( outp2 ) ;

out3 = new JLabel ( " Round To Hundredths " ) ;

c.add ( out3 ) ;

outp3 = new JTextField ( 5 ) ;

outp3.setEditable ( false ) ;

c.add ( outp3 ) ;

out4 = new JLabel ( " Round To Thousandths " ) ;

c.add ( out4 ) ;

outp4 = new JTextField ( 5 ) ;

outp4.setEditable ( false ) ;

c.add ( outp4 ) ;

b = new JButton ( " Calculate ! " ) ;

b.addActionListener ( this ) ;

c.add ( b ) ;
}

public void actionPerformed ( ActionEvent actionEvent )
{
outp1.setText ( Integer.toString ( NeerInteger ( Double.parseDouble ( input.getText () ) ) ) ) ;

outp2.setText ( Double.toString ( NeerTenth ( Double.parseDouble ( input.getText () ) ) ) ) ;

outp3.setText ( Double.toString ( NeerHund ( Double.parseDouble ( input.getText () ) ) ) ) ;

outp4.setText ( Double.toString ( NeerThou ( Double.parseDouble ( input.getText () ) ) ) ) ;

}

public int NeerInteger ( double a )
{
int y1 ;

y1 = ( int ) Math.floor ( a + 0.5 ) ;

return y1 ;
}

public double NeerTenth ( double b )
{
double y2 ;

y2 = Math.floor ( ( b * 10 + 0.5 ) / 10 ) ;

return y2 ;
}

public double NeerHund ( double c )
{
double y3 ;

y3 = Math.floor ( ( c * 100 + 0.5 ) / 100 ) ;

return y3 ;
}

public double NeerThou ( double d )
{
double y4 ;

y4 = Math.floor ( ( d * 1000 + 0.5 ) / 1000 ) ;

return y4 ;
}

}

Topic: setting window in exact position in stack Previous Topic   Next Topic Topic: help in my project: getting NullPointerException

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use