Ich fange grad mit Java an und habe nun vor mein erstes Programm darin zu schreiben. Und das soll einfach zwei Zahlen miteinander addieren. Leicht, ne?
Ich habe bisher die ganze Oberfläche schon fertig... also eine Form mit einem Button und zwei Textfeldern für die Zahlen. In einem Label was darunter angebracht ist soll dann das Ergebnis der Beiden Textfelder stehen sobald man auf den Button klickt... hier ist mein Code:
- Code: Alles auswählen
/*
A basic extension of the java.applet.Applet class
*/
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet
{
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
//symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setBackground(java.awt.Color.black);
setSize(583,336);
button1.setLabel("Berechnen");
add(button1);
button1.setBackground(java.awt.Color.black);
button1.setForeground(java.awt.Color.white);
button1.setBounds(228,240,132,24);
lblcaption.setText("Dieses Programm dient zur Berechnung zweier Zahlen. Bitte geben Sie die erste Zahl an:");
add(lblcaption);
lblcaption.setForeground(java.awt.Color.white);
lblcaption.setBounds(36,24,504,36);
txtzahl1.setText("Erste Zahl");
add(txtzahl1);
txtzahl1.setForeground(java.awt.Color.yellow);
txtzahl1.setBounds(216,60,156,24);
label1.setText("Und jetzt bitte die zweite Zahl:");
add(label1);
label1.setForeground(java.awt.Color.white);
label1.setBounds(216,120,168,30);
txtzahl2.setText("Zweite Zahl");
add(txtzahl2);
txtzahl2.setBackground(java.awt.Color.black);
txtzahl2.setForeground(java.awt.Color.yellow);
txtzahl2.setBounds(216,156,156,24);
lblergebnis.setText("Ergebnis");
add(lblergebnis);
lblergebnis.setForeground(java.awt.Color.cyan);
lblergebnis.setBounds(240,288,96,29);
//}}
//{{REGISTER_LISTENERS
SymMouse aSymMouse = new SymMouse();
this.addMouseListener(aSymMouse);
txtzahl1.addMouseListener(aSymMouse);
txtzahl2.addMouseListener(aSymMouse);
//}}
}
//{{DECLARE_CONTROLS
java.awt.Button button1 = new java.awt.Button();
java.awt.Label lblcaption = new java.awt.Label();
java.awt.TextField txtzahl1 = new java.awt.TextField();
java.awt.Label label1 = new java.awt.Label();
java.awt.TextField txtzahl2 = new java.awt.TextField();
java.awt.Label lblergebnis = new java.awt.Label();
//}}
class SymMouse extends java.awt.event.MouseAdapter
{
public void mousePressed(java.awt.event.MouseEvent event)
{
Object object = event.getSource();
if (object == Applet1.this)
Applet1_MousePressed(event);
else if (object == txtzahl1)
txtzahl1_MousePressed(event);
else if (object == txtzahl2)
txtzahl2_MousePressed(event);
}
}
void Applet1_MousePressed(java.awt.event.MouseEvent event)
{
// to do: code goes here.
}
void txtzahl1_MousePressed(java.awt.event.MouseEvent event)
{
// to do: code goes here.
txtzahl1.setText("");
}
void txtzahl2_MousePressed(java.awt.event.MouseEvent event)
{
// to do: code goes here.
txtzahl2.setText("");
}
}
Habe übrigens Javacafe zur Programmierung benutzt. Ich will später vl in na Firma Java proggen und ich lerne das grad auf so na Schule. Ich kann da doch ruhig mit so einem Programm lernen, oder? Oder meint ihr ich soll nen völlig normalen Compiler benutzten. Was verlangen die Firmen später von mir???
cya
David777