[Java] Wie stell ich andere Farben ein?

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von KoR!dOs, 14. Mai 2007 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 14. Mai 2007
    Wie stell ich andere Farben ein?

    Hi, ich wollte mal fragen, wie ich bei Java andere Farben einstelle. Die standard Farben kenn ich, aber wie siehts aus mit anderen. Wäre super, wenn ihr mir ein Beispiel geben könntet. Am besten hierbei:
    Code:
    import java.awt.*;
    import java.awt.event.*;
    
    /**********************************************************
    *
    * This class implements a simple phone GUI.
    * When creating a new object of this class
    * the GUI components, such as buttons, labels, etc. are
    * just displayed. They do not yet react on user actions,
    * such as pressing a button, etc.
    *
    * @author H. Diethelm, HTA Luzern
    * @version 1.0 12-06-2000
    * 
    **********************************************************/
    class JavaPhoneGUI extends Frame {
     
     // Declare and create key buttons
     Button key1 = new Button("1");
     Button key2 = new Button("2");
     Button key3 = new Button("3");
     Button key4 = new Button("4");
     Button key5 = new Button("5");
     Button key6 = new Button("6");
     Button key7 = new Button("7");
     Button key8 = new Button("8");
     Button key9 = new Button("9");
     Button key0 = new Button("0");
     Button keyNo = new Button("#");
     Button keyStar = new Button("*");
     
     // Declare and create other GUI elements
     TextField display = new TextField();
     Button hook = new Button("Hook off");
     Label state = new Label("ready");
     
     // Declare and create panels
     Panel keyPanel = new Panel();
     Panel keyDisplayPanel = new Panel();
     Panel hookStatePanel = new Panel();
     
     
     // Declare listener class for close box of frame
     class CloseListener extends WindowAdapter {
     public void windowClosing(WindowEvent e) {
     System.exit(0);
     }
     }
     // Alternatively you can implement the interface
     // WindowListener. But then every method must be
     // implemented! Also:
     // class CloseListener implements WindowListener { ...
     
     
     class HookListener implements ActionListener {
     // Is called when hook button is pressed
     public void actionPerformed(ActionEvent e) {
     if (e.getActionCommand().equals("Hook off")) {
     hook.setLabel("Hook on");
     state.setText("connected");
     } else {
     hook.setLabel("Hook off");
     state.setText("ready");
     display.setText("");
     }
     }
     }
     
     class KeyListener implements ActionListener {
     // Is called when key button is pressed
     public void actionPerformed(ActionEvent e) {
     if (state.getText().equals("ready")) {
     // Get label of pressed key button and write it to the display
     String no = display.getText() + e.getActionCommand();
     display.setText(no);
     }
     }
     } 
    
    
     // Constructor. Assembles and displays the GUI.
     JavaPhoneGUI() {
     // Initialise frame and GUI elements and
     setTitle("JavaPhone");
     setBackground(Color.lightGray);
     setResizable(false);
     display.setEditable(false);
     
     // Add listener objects to GUI elements
     addWindowListener(new CloseListener());
     hook.addActionListener(new HookListener());
     key1.addActionListener(new KeyListener());
     key2.addActionListener(new KeyListener());
     key3.addActionListener(new KeyListener());
     key4.addActionListener(new KeyListener());
     key5.addActionListener(new KeyListener());
     key6.addActionListener(new KeyListener());
     key7.addActionListener(new KeyListener());
     key8.addActionListener(new KeyListener());
     key9.addActionListener(new KeyListener());
     key0.addActionListener(new KeyListener());
     keyNo.addActionListener(new KeyListener());
     keyStar.addActionListener(new KeyListener());
     
     // Set layout of all panels and of frame
     keyPanel.setLayout(new GridLayout(4, 3, 20, 20));
     keyDisplayPanel.setLayout(new BorderLayout(20, 20));
     hookStatePanel.setLayout(new BorderLayout(20, 20));
     setLayout(new BorderLayout(20, 20));
     
     // Add key buttons to key panel
     keyPanel.add(key1);
     keyPanel.add(key2);
     keyPanel.add(key3);
     keyPanel.add(key4);
     keyPanel.add(key5);
     keyPanel.add(key6);
     keyPanel.add(key7);
     keyPanel.add(key8);
     keyPanel.add(key9);
     keyPanel.add(keyNo);
     keyPanel.add(key0);
     keyPanel.add(keyStar);
    
     // Assemble key/display panel
     keyDisplayPanel.add(display, BorderLayout.NORTH);
     keyDisplayPanel.add(keyPanel, BorderLayout.CENTER);
     
     // Assemble hook/state panel
     hookStatePanel.add(state, BorderLayout.NORTH);
     hookStatePanel.add(hook, BorderLayout.CENTER);
    
     // Add key/display panel and hook/state panel to frame
     add(hookStatePanel, BorderLayout.WEST);
     add(keyDisplayPanel, BorderLayout.CENTER);
     }
    }
    Vielen Dank schon mal

    Ps: Bw ist selbstverständlich
    Mfg
     
  2. 14. Mai 2007
    AW: Wie stell ich andere Farben ein?

    hi, versuch vorher mal ne farbe zu definieren.

    Constructor

    Color c = new Color(int red, int green, int blue)
    This creates a new color object that is a combination of red, green, and blue. The values of each color must be in the range 0-255.

    BSP:
    Color c = new Color(255, 255, 240);
    this.setBackground(c);
     
  3. 14. Mai 2007
    AW: Wie stell ich andere Farben ein?

    Danke für deine Antwort. Bw bekommste. Ich denke mal dann kann der Thread jetzt geschlossen werden.
    MfG
     
  4. 14. Mai 2007
    AW: Wie stell ich andere Farben ein?

    Kannst über themenoptionen--> Thema schließen auch selber ,)

    [X] Erledigt

    Knusperkeks
     
  5. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.