AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit Mausereignis (JAVA)

Ein Thema von Dannyboy · begonnen am 30. 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:00
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
Antwort Antwort


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 00:42 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