AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Problem mit Mausereignis (JAVA)

Ein Thema von Dannyboy · begonnen am 30. Mär 2004 · letzter Beitrag vom 31. Mär 2004
Antwort Antwort
Dannyboy

Registriert seit: 4. Aug 2003
Ort: Delphi-Heaven
418 Beiträge
 
Delphi 7 Personal
 
#1

Problem mit Mausereignis (JAVA)

  Alt 30. Mär 2004, 11:07
Guuuden zusammen,
ich habe das Problem, dass meine Testbuttons (bisher "exit" und "cancel")
nicht auf das Mausereignis Pressed reagieren:
Wir haben keine Ahnung, woran das liegen können, haben alles mögliche versucht.

Hier ist der Quelltext:
Code:
/**
 *@author Dannyboy, Mike T.
*/ 
 
import java.io.*;
import java.awt.*;      // für Fenster
import java.awt.event.*;   // Für Adapter

public class Mainframe extends Frame {

//******************************************************************************************//

// KONSTRUKTOREN

  Mainframe(String title) {          
     this.f = new Frame();
     f.setLayout(null);         
     f.setSize(clientWidth, clientHeight);    
     f.setTitle(title);     
     f.addWindowListener(new MyWindowAdapter());
     setDesign();    
     myMouse = new MyMouseAdapter();
     f.addMouseListener(myMouse);    
     f.show();
  }   
 
//******************************************************************************************//
 
        public Frame f = null;
 
// ATTRIBUTE (KONSTANTEN)

   final private int clientWidth = 750; // Breite des Clientbereichs
   final private int clientHeight = 550; // Höhe des Clientbereichs
   final private int leftAlign = 20; // Position der linken Zentrierung    
   final private int labelheight = 25; // Standardhöhe eines Labels
   final private int buttonheight = 30; // Standardhöhe eines Buttons
   final private int textfieldheight = buttonheight; // Standardhöhe eines textfeldes

// ATTRIBUTE (VARIABLEN)   
           
    // Textfelder    
   public TextField stdIn = null;
   public TextField rCode = null;   
    // Textareas   
   public TextArea stdOut = null;
   public TextArea stdErr = null;
    // Labels      
   public Label stdIn_Lab = null;
   public Label stdErr_Lab = null;
   public Label stdOut_Lab = null;
   public Label rCode_Lab = null;
    // Buttons   
   public Button ok       = null;
   public Button cancel   = null;
   public Button snap     = null;
   public Button exit     = null;
   
   MyMouseAdapter myMouse = null;      
   
            
//******************************************************************************************//
 
  // Methode legt das komplette Design des Formulars fest.
 
  private void setDesign() {
     final int middleX = clientWidth / 2;    
     
     createLabel(stdIn_Lab, leftAlign, 25, 90, labelheight, "<Eingabe>");
     createTextField(stdIn, leftAlign, 50, 275, textfieldheight, "");
     createButton(ok, leftAlign, 90, 85, buttonheight, "OK");
   createButton(snap, 115, 90, 85, buttonheight, "SNAP-MENU");
   createButton(cancel, 210, 90, 85, buttonheight, "CANCEL");   
   
   createLabel(stdErr_Lab, leftAlign, 130, 100, labelheight, "<Standard Error>");
   createTextArea(stdErr, leftAlign, 160, 290, 295, "<Dies ist Standard Error>");
   createLabel(rCode_Lab, leftAlign, 465, 90, labelheight, "<return code>");
   createTextField(rCode, leftAlign, 495, 275, textfieldheight, "");   
   
   createLabel(stdOut_Lab, middleX, 25, 90, labelheight, "<Standard Out>");
   createTextArea(stdOut, middleX, 50, middleX - 20, 430, "<Dies ist Standard Out>");
      
   createButton(exit, middleX, 495, middleX - 20, buttonheight, "Close Window");
  }
 
 
//******************************************************************************************// 
 
// GETTER
   
   
//******************************************************************************************//
 
// SETTER
 
 
//******************************************************************************************//
 
 // Methode erstellt ein Textfeld (einzeilige Komponente)
 
 private void createTextField(TextField instance, int x, int y, int width, int height, String s) {     
    instance = new TextField(s);    
     f.add(instance);
//     instance.setBackground(bg);
     instance.setBounds(x, y, width, height);
     instance.show();
 }

//******************************************************************************************//
 
// Methode erstellt eine Textarea (mehrzeilige Komponente)
 
 private void createTextArea(TextArea instance, int x, int y, int width, int height, String s) {     
    instance = new TextArea(s);    
     f.add(instance);
//     instance.setBackground(bg);
     instance.setBounds(x, y, width, height);
     instance.show();
 }

//******************************************************************************************//
 
// Methode erstellt ein Label
 
 private void createLabel(Label instance, int x, int y, int width, int height, String s) {
    instance = new Label(s);    
     f.add(instance);
     instance.setBounds(x, y, width, height);
     instance.show();
 } 
 
//******************************************************************************************//
 
// Methode erstellt einen Button
 
 private void createButton(Button instance, int x, int y, int width, int height, String s) {
    instance = new Button(s);    
     f.add(instance);
     instance.setBounds(x, y, width, height);    
     instance.addMouseListener(myMouse);   
     instance.show();    
 } 
 
//******************************************************************************************//
//******************************************************************************************//
//******************************************************************************************//

  // Unterklasse um Window-Events (OOP-Ereignisse) zu steuern

     public class MyWindowAdapter extends WindowAdapter {    
        public void windowClosing (WindowEvent e) {
           System.exit(0);
        }
     }
               
//******************************************************************************************//     
//******************************************************************************************//     
//******************************************************************************************//

  // Unterklasse um Mouse-Events (OOP-Ereignisse) zu steuern

    public class MyMouseAdapter extends MouseAdapter {
                public void mousePressed(MouseEvent e) {
              Object o = e.getSource();
              if (o == ok)
                 ok_Pressed(e);
              else if (o == cancel)
                 cancel_Pressed(e);
              else if (o == snap)
                 snap_Pressed(e);
              else if (o == exit)
                 exit_Pressed(e);                                            
              }
           }
                       
//******************************************************************************************//     
//******************************************************************************************//     
//******************************************************************************************//

// Mouse/Button Events

   public void ok_Pressed(MouseEvent e){}
   public void cancel_Pressed(MouseEvent e){
      stdIn.setText("");      
   }
   public void snap_Pressed(MouseEvent e){}
   public void exit_Pressed(MouseEvent e){
      System.exit(0);      
   }

//******************************************************************************************//

   public static void main(String[] args) {
      Mainframe testframe = new Mainframe("JAVIX 2.0");
   }
}
How much wood would a wood-chuck chuck if a wood-chuck would chuck wood?
Check this out.
DANNYBOY
  Mit Zitat antworten Zitat
Jörn

Registriert seit: 5. Sep 2003
Ort: Helmstedt
312 Beiträge
 
#2

Re: Problem mit Mausereignis (JAVA)

  Alt 30. Mär 2004, 12:29
Ein Thread reicht vollkommen!
http://www.delphipraxis.net/internal...ct.php?t=21965
  Mit Zitat antworten Zitat
Dannyboy

Registriert seit: 4. Aug 2003
Ort: Delphi-Heaven
418 Beiträge
 
Delphi 7 Personal
 
#3

Re: Problem mit Mausereignis (JAVA)

  Alt 30. Mär 2004, 13:10
Ja, da hast Du vollkommen Recht.
@Admins:
Löscht mal bitte diesen Threat. Ist ausversehen ein Doppelpost.
How much wood would a wood-chuck chuck if a wood-chuck would chuck wood?
Check this out.
DANNYBOY
  Mit Zitat antworten Zitat
Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#4

Re: Problem mit Mausereignis (JAVA)

  Alt 30. Mär 2004, 15:21
Zitat von Dannyboy:
Löscht mal bitte diesen Threat.
Freudsche Fehlleistung?

Zitat:
ich habe das Problem, dass meine Testbuttons (bisher "exit" und "cancel")
nicht auf das Mausereignis Pressed reagieren:

Wir haben keine Ahnung, woran das liegen können, haben alles mögliche versucht.
[edit3]Ich sollte nichts posten, wenn ich drei Tage hintereinander nur 4 Stunden geschlafen habe... Wie auch immer, wenn die Buttons erstellt werden, ist myMouse immer null, sagt mein Debugger. Warum, will ich jetzt nicht weiter ergründen, dazu bin ich nämlich anscheinend nicht mehr imstande.[/edit3]
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat
Benutzerbild von d3g
d3g

Registriert seit: 21. Jun 2002
602 Beiträge
 
#5

Re: Problem mit Mausereignis (JAVA)

  Alt 30. Mär 2004, 16:10
Ha! Ich hab's jetzt doch geschafft.

Zwei Fehler hast du gemacht:
1. Du hast setDesign() aufegrufen, bevor du myMouse instanziert hast, so dass alle Buttons mit null als Listener gespeist wurden.
2. Du weist den Feldern ok, cancel, etc. nichts zu. Ja, instance wird in den Funktionen erzeugt, aber das hat keine Auswirkung auf die Variable, die du übergibst. Warum, frag mich jetzt bitte nicht, ich habe es auch schon so gemacht wie du und das Stichwort Call-by-Reference sollte eigentlich auxch bedeuten, dass dein Ansatz funktioniert. Das tut es nur nicht. Keine Ahnung, warum (in meinem Zustand nicht). Wie auch immer, so geht's:

Code:
// KONSTRUKTOREN

   Mainframe(String title) {
      this.f = new Frame();
      f.setLayout(null);
      f.setSize(clientWidth, clientHeight);
      f.setTitle(title);
      f.addWindowListener(new MyWindowAdapter());
      myMouse = new MyMouseAdapter();
      f.addMouseListener(myMouse);
      setDesign();
      f.show();
   }
 
//******************************************************************************************//
 
  // Methode legt das komplette Design des Formulars fest.
 
   private void setDesign() {
      final int middleX = clientWidth / 2;
     
       stdIn_Lab = createLabel(leftAlign, 25, 90, labelheight, "<Eingabe>");
       stdIn = createTextField(leftAlign, 50, 275, textfieldheight, "");
      ok = createButton(leftAlign, 90, 85, buttonheight, "OK");
      snap = createButton(115, 90, 85, buttonheight, "SNAP-MENU");
      cancel = createButton(210, 90, 85, buttonheight, "CANCEL");
   
      stdErr_Lab = createLabel(leftAlign, 130, 100, labelheight, "<Standard Error>");
      stdErr = createTextArea(leftAlign, 160, 290, 295, "<Dies ist Standard Error>");
       rCode_Lab = createLabel(leftAlign, 465, 90, labelheight, "<return code>");
      rCode = createTextField(leftAlign, 495, 275, textfieldheight, "");
   
      stdOut_Lab = createLabel(middleX, 25, 90, labelheight, "<Standard Out>");
      stdOut = createTextArea(middleX, 50, middleX - 20, 430, "<Dies ist Standard Out>");
     
      exit = createButton(middleX, 495, middleX - 20, buttonheight, "Close Window");
   }
 
 
//******************************************************************************************//
 
// Methode erstellt ein Textfeld (einzeilige Komponente)

   private TextField createTextField(int x, int y, int width, int height, String s) {
      TextField instance = new TextField(s);
      f.add(instance);
   //      instance.setBackground(bg);
      instance.setBounds(x, y, width, height);
      instance.show();
      return instance;
   }

//******************************************************************************************//

// Methode erstellt eine Textarea (mehrzeilige Komponente)
 
   private TextArea createTextArea(int x, int y, int width, int height, String s) {
      TextArea instance = new TextArea(s);
      f.add(instance);
   //     instance.setBackground(bg);
      instance.setBounds(x, y, width, height);
      instance.show();
      return instance;
    }

//******************************************************************************************//
 
// Methode erstellt ein Label
 
   private Label createLabel(int x, int y, int width, int height, String s) {
      Label instance = new Label(s);
      f.add(instance);
      instance.setBounds(x, y, width, height);
      instance.show();
      return instance;
    }
 
//******************************************************************************************//
 
// Methode erstellt einen Button
 
    private Button createButton(int x, int y, int width, int height, String s) {
      Button instance = new Button(s);
      f.add(instance);
      instance.setBounds(x, y, width, height);
      instance.addMouseListener(myMouse);
      instance.show();
      return instance;
    }
-- Crucifixion?
-- Yes.
-- Good. Out of the door, line on the left, one cross each.
  Mit Zitat antworten Zitat
Dannyboy

Registriert seit: 4. Aug 2003
Ort: Delphi-Heaven
418 Beiträge
 
Delphi 7 Personal
 
#6

Re: Problem mit Mausereignis (JAVA)

  Alt 31. Mär 2004, 10:05
Fehler Numero Uno kann ich nachvollziehen, aber den 2. Fehler ...
Das verwirrt mich, denn ich dachte, innerhalb einer Klasse sind alle (!) Argumente
CALL BY REFERENCE. Na ja gut, dann mach' ich aus den Voids eben Funktionen.
Dank' Dir, Mann.
How much wood would a wood-chuck chuck if a wood-chuck would chuck wood?
Check this out.
DANNYBOY
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz