A
ayk
Gast
hallo,
ich hab ein problem mit meinem quellcode.
und zwar weis ich nicht, wie ich die einzelnen Methoden im Programm in einzelnen java dateien zerlegen kann.
mit der main hab ich es geschafft. das ging ganz einfach.
aber z.B. die Taschenrechner() hab ich keine ahnung, wie ich die raus krieg?????
kann mir da bitte jemand helfen.
ich hoffe die Frage ist verständlich gestellt
danke
Edit by Beni: Code eingerückt.
ich hab ein problem mit meinem quellcode.
und zwar weis ich nicht, wie ich die einzelnen Methoden im Programm in einzelnen java dateien zerlegen kann.
mit der main hab ich es geschafft. das ging ganz einfach.
aber z.B. die Taschenrechner() hab ich keine ahnung, wie ich die raus krieg?????
kann mir da bitte jemand helfen.
ich hoffe die Frage ist verständlich gestellt
danke
Code:
import java.awt.*;
import java.awt.event.*;
public class Taschenrechner extends Frame implements WindowListener, ActionListener{
Label l1;
TextField t1;
Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, bplus, bminus, bmal,
bgleich, bpunkt, bclear, bgeteilt;
boolean Rechne = true;
double Zahl = 0;
String Operation = "";
/**
* erstellt die Oberflaeche des Taschenrechners
*/
public Taschenrechner()
{
Frame window = new Frame( "" );
window.addWindowListener( this );
window.setTitle( "Roche" );
window.setSize( 250, 340 );
window.setLocation( 200, 200 );
window.setBackground( Color.red );
/**
* erstellt das Anzeigefeld des Taschenrechners
*/
t1 = new TextField( "" );
t1.setSize( 130, 30 );
t1.setLocation( 30, 30 );
t1.setEditable( false );
window.add( t1 );
/**
* erstellt die Buttons (0-9) des Taschenrechners
*/
b7 = new Button( "7" );
b7.setSize( 40, 40 );
b7.setLocation( 30, 80 );
b7.addActionListener( this );
window.add( b7 );
b8 = new Button( "8" );
b8.setSize( 40, 40 );
b8.setLocation( 80, 80 );
b8.addActionListener( this );
window.add( b8 );
b9 = new Button( "9" );
b9.setSize( 40, 40 );
b9.setLocation( 130, 80 );
b9.addActionListener( this );
window.add( b9 );
b4 = new Button( "4" );
b4.setSize( 40, 40 );
b4.setLocation( 30, 140 );
b4.addActionListener( this );
window.add( b4 );
b5 = new Button( "5" );
b5.setSize( 40, 40 );
b5.setLocation( 80, 140 );
b5.addActionListener( this );
window.add( b5 );
b6 = new Button( "6" );
b6.setSize( 40, 40 );
b6.setLocation( 130, 140 );
b6.addActionListener( this );
window.add( b6 );
b1 = new Button( "1" );
b1.setSize( 40, 40 );
b1.setLocation( 30, 200 );
b1.addActionListener( this );
window.add( b1 );
b2 = new Button( "2" );
b2.setSize( 40, 40 );
b2.setLocation( 80, 200 );
b2.addActionListener( this );
window.add( b2 );
b3 = new Button( "3" );
b3.setSize( 40, 40 );
b3.setLocation( 130, 200 );
b3.addActionListener( this );
window.add( b3 );
b0 = new Button( "0" );
b0.setSize( 40, 40 );
b0.setLocation( 30, 260 );
b0.addActionListener( this );
window.add( b0 );
/**
* erstellt die Operator-Buttons (C, +, -, *, /, =, .) des
* Taschenrechners
*/
bclear = new Button( "C" );
bclear.setSize( 40, 40 );
bclear.setLocation( 180, 30 );
bclear.addActionListener( this );
window.add( bclear );
bplus = new Button( "+" );
bplus.setSize( 40, 40 );
bplus.setLocation( 180, 140 );
bplus.addActionListener( this );
window.add( bplus );
bminus = new Button( "-" );
bminus.setSize( 40, 40 );
bminus.setLocation( 180, 200 );
bminus.addActionListener( this );
window.add( bminus );
bpunkt = new Button( "." );
bpunkt.setSize( 40, 40 );
bpunkt.setLocation( 80, 260 );
bpunkt.addActionListener( this );
window.add( bpunkt );
bgleich = new Button( "=" );
bgleich.setSize( 40, 40 );
bgleich.setLocation( 130, 260 );
bgleich.addActionListener( this );
window.add( bgleich );
bmal = new Button( "*" );
bmal.setSize( 40, 40 );
bmal.setLocation( 180, 260 );
bmal.addActionListener( this );
window.add( bmal );
bgeteilt = new Button( "/" );
bgeteilt.setSize( 40, 40 );
bgeteilt.setLocation( 180, 80 );
bgeteilt.addActionListener( this );
window.add( bgeteilt );
/**
* macht die Oberfläche des Taschenrechners sichtbar
*/
l1 = new Label( "" );
window.add( l1 );
window.setVisible( true );
}// Ende Taschenrechner
/**
* Wird aufgerufen, wenn das Fenster geschlossen wird
*/
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
/**
* Wird aufgerufen, wenn das Fenster aktiviert wird
*/
public void windowActivated( WindowEvent e ) {
}
/**
* Wird aufgerufen, wenn das Fenster mit dispose() geschlossen wurde
*/
public void windowClosed( WindowEvent e ) {
}
/**
* Wird aufgerufen, wenn das Fenster deaktiviert wird
*/
public void windowDeactivated( WindowEvent e ) {
}
/**
* Wird aufgerufen, wenn das Fenster wieder hochgeholt wird
*/
public void windowDeiconified( WindowEvent e ) {
}
/**
* Wird aufgerufen, wenn das Fenster zum Icon verkleinert wird
*/
public void windowIconified( WindowEvent e ) {
}
/**
* Wird aufgerufen, wenn Fenster geöffnet wurde
*/
public void windowOpened( WindowEvent e ) {
}
/**
* Erkennung von Eingaben
*/
public void actionPerformed( ActionEvent ea ) {
int h;
String inh = new String();
String but = ea.getActionCommand();
if( but == "0" ){
ziffer( "0" );
}
else if( but == "1" ){
ziffer( "1" );
}
else if( but == "2" ){
ziffer( "2" );
}
else if( but == "3" ){
ziffer( "3" );
}
else if( but == "4" ){
ziffer( "4" );
}
else if( but == "5" ){
ziffer( "5" );
}
else if( but == "6" ){
ziffer( "6" );
}
else if( but == "7" ){
ziffer( "7" );
}
else if( but == "8" ){
ziffer( "8" );
}
else if( but == "9" ){
ziffer( "9" );
}
else if( but == "+" ){
verkn( "+" );
}
else if( but == "-" ){
verkn( "-" );
}
else if( but == "*" ){
verkn( "*" );
}
else if( but == "/" ){
verkn( "/" );
}
else if( but == "." ){
if( Rechne ){
t1.setText( "0." );
Rechne = false;
}
else{
inh = new String( t1.getText() );
h = inh.indexOf( "." );
if( h < 0 ){
t1.setText( t1.getText() + "." );
}
}// else
}
else if( but == "C" ){
t1.setText( "" );
Rechne = true;
Zahl = 0;
Operation = "";
}
else if( but == "=" ){
verkn( "" );
}
}// Ende actionPerformed
/**
* schreib in Display
*/
public void ziffer( String s ) {
if( Rechne ){
t1.setText( s );
Rechne = false;
}
else{
String inh = new String( t1.getText() );
/** zähle die Punkte* */
int h = inh.indexOf( "." );
/** bei 6 ohne punkt oder 25 mit punkt* */
if( ((h < 0) && (inh.length() < 6))
|| ((h > 0) && (inh.length() < 25)) )
t1.setText( t1.getText() + s );
else
return;
}
}// Ende ziffer
/**
* durchführung der Rechnung
*/
public void verkn( String s ) {
Double wert;
Rechne = true;
try{
if( Operation == "" ){
wert = new Double( t1.getText() );
Zahl = wert.doubleValue();
Operation = s;
}
else{
wert = new Double( t1.getText() );
if( Operation == "+" ){
Zahl = Zahl + wert.doubleValue();
}
else if( Operation == "-" ){
Zahl = Zahl - wert.doubleValue();
}
else if( Operation == "*" ){
Zahl = Zahl * wert.doubleValue();
}
else if( Operation == "/" ){
Zahl = Zahl / wert.doubleValue();
}
Operation = s;
t1.setText( s.valueOf( Zahl ) );
}
}// try
catch( ArithmeticException e ){
t1.setText( "Error:" + e );
ziffer( "" );
}
catch( Throwable e ){
t1.setText( "Fehler:" + e );
ziffer( "" );
}
}// Ende verkn
/**
* main
*/
public static void main( String[] args ) {
Taschenrechner meinFenster = new Taschenrechner();
}// Ende main
}
Edit by Beni: Code eingerückt.