stell mich blöd an
-
import java.awt.*; import javax.swing.*; public class GUI extends JFrame{ private Container cont; private JButton bt1 , bt2; private ButtonGroup btngrp; private FlowLayout flow1 , flow2; private JPanel pan1 , pan2; private JLabel lb1; private JList lst; private JScrollPane scrollpan; private DefaultListModel lstMod; private JTextField tf1; public GUI(){ cont = getContentPane(); /*----------------NORTH---Labe---TextField-------------*/ lb1 = new JLabel("Was?"); tf1 = new JTextField("",20); flow1 = new FlowLayout(); pan1 = new JPanel(flow1); pan1.add(lb1); pan1.add(tf1); cont.add(BorderLayout.NORTH, pan1); /*----------------CENTER---Liste----------------*/ lstMod = new DefaultListModel(); lst = new JList(lstMod); scrollpan = new JScrollPane(lst); cont.add(BorderLayout.CENTER, scrollpan); /*----------------NORTH---Buttons----------------*/ bt1 = new JButton("Eingabe");bt1.setEnabled(true); bt2 = new JButton("Entfernen");bt2.setEnabled(false); flow2 = new FlowLayout(); pan2 = new JPanel(flow2); pan2.add(bt1); pan2.add(bt2); cont.add(BorderLayout.SOUTH, pan2); /*---------------------------------------*/ bt1.addActionListener(new MyButtonAction(this)); addWindowListener(new MyWindowListener()); /*----------------Fenster----------------*/ setSize(350,350); setTitle("Einkaufsliste"); setLocation(250,250); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } public void addElementInListe(String param){ lstMod.addElement(param); } public String getTextFieldText() { return tf1.getText(); } public void delElementVonListe(String param){ lstMod.addElement(param); } }
public class mainGUI { public static void main(String[] args) { GUI f1 = new GUI(); } }
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyButtonAction implements ActionListener{ private GUI gui; public MyButtonAction(GUI pGUI){ gui = pGUI; } public void actionPerformed(ActionEvent e){ gui.addElementInListe(gui.getTextFieldText()); //gui.JButton(bt1.setEnabled(false)); } public void Positionloeschen(ActionEvent e){ gui.addElementInListe(gui.getTextFieldText()); //gui.JButton(bt1.setEnabled(false)); } }
import java.awt.event.WindowEvent; import java.awt.event.WindowListener; public class MyWindowListener implements WindowListener { public void windowActivated(WindowEvent e) { System.out.println("windowActivated..."); } public void windowClosed(WindowEvent e) { System.out.println("windowClosed..."); } public void windowClosing(WindowEvent e) { System.out.println("windowClosing..."); } public void windowDeactivated(WindowEvent e) { System.out.println("WindowDeactivated..."); } public void windowDeiconified(WindowEvent e) { System.out.println("windowDeiconified..."); } public void windowIconified(WindowEvent e) { System.out.println("windowInconified..."); } public void windowOpened(WindowEvent e) { System.out.println("windowOpenend..."); } }
ziehl ist es das ich Buttons nur benutzen kann wenn ich sie bracuh, also wenn ich text makiere (lösche)
oder wenn ich text eingeb (hinzufüge)freizeichen sollen am anfang und ende eines wortes nicht anerkannt werden z.B. eingabe: " dsfsd "
wäre:"dsfsd"
eingaben mit mausklick und mit tastaturbitte hilfe ich komm nicht weiter