Hallo zusammen.
Wir sitzen grad in der Schule an nem Projekt mit Java. Wir wollen ein paar Textfelder und einige Buttons in einer Grafik einfügen. Die Textfelder sollen beim drücken der Buttons raufzählen und dann die neuen Werte ausgeben.
Unser Problem ist jetzt jedoch, das wir es nich schaffen, diese auf der Grafik bzw in der Grafik anzuzeigen.
Entweder wird die Grafik von den Buttons und Textfeldern überlappt oder andersrum.
Hab schon einige Docs durch, darunter auch Java-Insel 4 und 5.
Wisst ihr vll noch ne Möglichkeit?
Hier mal unser Code:
Grafik-Ausgabe:
---------------------------------------------
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung.
*
* @version 1.0 vom 18.01.2007
* @dibz
*/
public class woj extends Frame {
// Anfang Variablen
// Ende Variablen
public woj(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); } });
int frameWidth = 800;
int frameHeight = 630;
setSize(frameWidth, frameHeight);
// Anfang Komponenten
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void paint(Graphics g)
{
Image img;
img = getToolkit().getImage("woj.jpg");
g.drawImage(img,0,30,this);
}
// Ende Ereignisprozeduren
public static void main(String[] args) {
new woj("woj");
}
}
------------------------------------------------------------
Buttons:
-----------------------------------------
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung.
*
* @version 1.0 vom 18.01.2007
* @dibz
*/
public class wojbutton extends Frame {
// Anfang Variablen
private Button button1 = new Button();
private Button button2 = new Button();
private Button button3 = new Button();
private Button button4 = new Button();
private TextField textField1 = new TextField();
private TextField textField2 = new TextField();
private TextField textField3 = new TextField();
private int a = 0;
private int b = 0;
private int c = 0;
// Ende Variablen
public wojbutton(String title)
{
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); } });
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Panel cp = new Panel(null);
add(cp);
// Anfang Komponenten
button1.setBounds(300, 80, 73, 57);
button1.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button1.setLabel("+");
cp.add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } });
button2.setBounds(632, 168, 73, 57);
button2.setLabel("+");
cp.add(button2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button2ActionPerformed(evt); } });
/*button3.setBounds(632, 40, 73, 57);
button3.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button3.setLabel("+");
cp.add(button3);
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } }); */
/*button4.setBounds(632, 10, 73, 57);
button4.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button4.setLabel("+");
cp.add(button1);
button4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } }); */
textField1.setBounds(200, 80, 89, 53);
textField1.setEditable(false);
textField1.setBackground(Color.YELLOW);
textField1.setText(" "+ a);
cp.add(textField1);
textField2.setBounds(200, 168, 89, 53);
textField2.setEditable(false);
textField2.setBackground(Color.YELLOW);
textField2.setText(" " + b);
cp.add(textField2);
textField3.setBounds(200, 264, 89, 53);
textField3.setEditable(false);
textField3.setBackground(Color.YELLOW);
textField3.setText(" ");
cp.add(textField3);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void button1ActionPerformed(ActionEvent evt)
{
if (evt.getSource()== button1)
{
a=a+1;
textField1.setText("" + a);
textField3.setText("" + (a+b));
}
}
public void button2ActionPerformed(ActionEvent evt)
{
if (evt.getSource()== button2)
{
b=b+1;
textField2.setText("" + b);
textField3.setText("" + (a+b));
}
}
// Ende Ereignisprozeduren
public static void main(String[] args)
{
new wojbutton("wojbutton");
}
}
-------------------
Wir sitzen grad in der Schule an nem Projekt mit Java. Wir wollen ein paar Textfelder und einige Buttons in einer Grafik einfügen. Die Textfelder sollen beim drücken der Buttons raufzählen und dann die neuen Werte ausgeben.
Unser Problem ist jetzt jedoch, das wir es nich schaffen, diese auf der Grafik bzw in der Grafik anzuzeigen.
Entweder wird die Grafik von den Buttons und Textfeldern überlappt oder andersrum.
Hab schon einige Docs durch, darunter auch Java-Insel 4 und 5.
Wisst ihr vll noch ne Möglichkeit?
Hier mal unser Code:
Grafik-Ausgabe:
---------------------------------------------
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung.
*
* @version 1.0 vom 18.01.2007
* @dibz
*/
public class woj extends Frame {
// Anfang Variablen
// Ende Variablen
public woj(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); } });
int frameWidth = 800;
int frameHeight = 630;
setSize(frameWidth, frameHeight);
// Anfang Komponenten
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void paint(Graphics g)
{
Image img;
img = getToolkit().getImage("woj.jpg");
g.drawImage(img,0,30,this);
}
// Ende Ereignisprozeduren
public static void main(String[] args) {
new woj("woj");
}
}
------------------------------------------------------------
Buttons:
-----------------------------------------
import java.awt.*;
import java.awt.event.*;
/**
*
* Beschreibung.
*
* @version 1.0 vom 18.01.2007
* @dibz
*/
public class wojbutton extends Frame {
// Anfang Variablen
private Button button1 = new Button();
private Button button2 = new Button();
private Button button3 = new Button();
private Button button4 = new Button();
private TextField textField1 = new TextField();
private TextField textField2 = new TextField();
private TextField textField3 = new TextField();
private int a = 0;
private int b = 0;
private int c = 0;
// Ende Variablen
public wojbutton(String title)
{
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { System.exit(0); } });
int frameWidth = 800;
int frameHeight = 600;
setSize(frameWidth, frameHeight);
Panel cp = new Panel(null);
add(cp);
// Anfang Komponenten
button1.setBounds(300, 80, 73, 57);
button1.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button1.setLabel("+");
cp.add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } });
button2.setBounds(632, 168, 73, 57);
button2.setLabel("+");
cp.add(button2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button2ActionPerformed(evt); } });
/*button3.setBounds(632, 40, 73, 57);
button3.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button3.setLabel("+");
cp.add(button3);
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } }); */
/*button4.setBounds(632, 10, 73, 57);
button4.setFont (new Font("MS Sans Serif", Font.PLAIN, 12));
button4.setLabel("+");
cp.add(button1);
button4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
button1ActionPerformed(evt); } }); */
textField1.setBounds(200, 80, 89, 53);
textField1.setEditable(false);
textField1.setBackground(Color.YELLOW);
textField1.setText(" "+ a);
cp.add(textField1);
textField2.setBounds(200, 168, 89, 53);
textField2.setEditable(false);
textField2.setBackground(Color.YELLOW);
textField2.setText(" " + b);
cp.add(textField2);
textField3.setBounds(200, 264, 89, 53);
textField3.setEditable(false);
textField3.setBackground(Color.YELLOW);
textField3.setText(" ");
cp.add(textField3);
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void button1ActionPerformed(ActionEvent evt)
{
if (evt.getSource()== button1)
{
a=a+1;
textField1.setText("" + a);
textField3.setText("" + (a+b));
}
}
public void button2ActionPerformed(ActionEvent evt)
{
if (evt.getSource()== button2)
{
b=b+1;
textField2.setText("" + b);
textField3.setText("" + (a+b));
}
}
// Ende Ereignisprozeduren
public static void main(String[] args)
{
new wojbutton("wojbutton");
}
}
-------------------