Welcome to Firefox for Android Add-ons.
Add extra features and styles to make Firefox for Android your own.
CloseReview for Forestle by Tiger19
Rated 3 out of 5 stars
L1
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.io.*;
public class Lebensmittel extends JFrame implements ActionListener, ListSelectionListener{
Artikel[] aArray = new Artikel[10];
private JLabel ueberschrift = new JLabel("L ");
private JLabel artnr = new JLabel("ArtNr: ");
private JLabel preis = new JLabel("Preis: ");
private JLabel menge = new JLabel("Menge: ");
private JLabel hilfelement1 = new JLabel(" ");
private JLabel hilfelement2 = new JLabel(" ");
private JButton element1 = new JButton("Bestellen");
private JButton element2 = new JButton("Beenden");
//Textfeld:
private JTextField textfeld1 = new JTextField();
private JTextField textfeld2 = new JTextField();
private JTextField textfeld3 = new JTextField();
//Array für Liste:
private static final String[] BESCHREIBUNG = {"", "", "", "", "","","","","",""};
private static final String[] ARTIKELNR = {"", "", "", "", "","","","","",""};
private static final String[] PREIS = {"", "", "", "", "","","","","",""};
private static final String[] BILD = {"G:\\vorgabe\\bild1.jpg", "G:\\vorgabe\\", "G:\\vorgabe\\", "G:\\vorgabe\\", "G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\","G:\\vorgabe\\"};
private JList list;
//Bild:
private String dateiname;
private String dateinamewahl;
private Image ibild;
private MeinJPanel panel_bild = new MeinJPanel(200,160,ibild);
public Lebensmittel (String titel) {
super(titel);
//aArray
//Container:
Container cp = getContentPane();
//Layout:
cp.setLayout(new FlowLayout(FlowLayout.CENTER));
//Panel:
JPanel panel_ueberschrift = new JPanel();
JPanel panel_list = new JPanel();
JPanel panel_a = new JPanel();
JPanel panel_a_untereinander = new JPanel();
//Bild:
dateiname = "G:\\vorgabe\\start.jpg";
//Image erzeugen
Toolkit tk = Toolkit.getDefaultToolkit();
ibild = tk.getImage(dateiname);
panel_bild = new MeinJPanel(200, 400, ibild);
//Layout Überschrift:
panel_ueberschrift.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
//Panel Liste:
panel_list.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
//Layout a:
panel_a.setLayout(new FlowLayout(FlowLayout.LEFT,0,10));
panel_a_untereinander.setLayout(new GridLayout(6,1,0,10));
//Layout Bild:
panel_bild.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
//Panel Überschrift:
ueberschrift.setFont(new Font("Serif", Font.BOLD, 30));
cp.add(panel_ueberschrift);
panel_ueberschrift.add(ueberschrift);
//Liste:
list = new JList(BESCHREIBUNG);
list.setSelectedIndex(2); //In der Liste an welcher Stelle selektieren.
list.setVisibleRowCount(3); //Länge der Liste setzen.
list.setFixedCellWidth(420); //Breite der Liste setzen.
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
//list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
//Scrollbar Liste:
JPanel scroll= new JPanel();
JScrollPane scrollPane = new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.add(scrollPane);
panel_list.add(scroll);
list.addListSelectionListener(this);
//Panel a:
cp.add(panel_a_untereinander);
panel_a_untereinander.add(artnr);
panel_a_untereinander.add(textfeld1);
panel_a_untereinander.add(preis);
panel_a_untereinander.add(textfeld2);
panel_a_untereinander.add(menge);
panel_a_untereinander.add(textfeld3);
panel_a_untereinander.add(hilfelement1);
panel_a_untereinander.add(element1);
panel_a_untereinander.add(hilfelement2);
panel_a_untereinander.add(element2);
//Vereinigung a:
panel_a.add(panel_a_untereinander);
//Panel Bild:
cp.add(panel_bild);
//Panel a:
cp.add(panel_a);
//Panel List:
cp.add(panel_list);
element1.addActionListener(this);
element2.addActionListener(this);
list.addListSelectionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
//Button Beenden:
if (e.getActionCommand().equals("Beenden"))
System.exit(0);
else
System.out.println(e.getActionCommand());
//Button:
String ergebnis1 = textfeld1.getText();
System.out.println("Artikelnummer: " + ergebnis1);
String ergebnis2 = textfeld2.getText();
System.out.println("Preis: " + ergebnis2);
String ergebnis3 = textfeld3.getText();
System.out.println("Menge: " + ergebnis3);
//Speicherung:
String s = "Artikelnummer: " + ergebnis1 + "\n" + "Preis: " + ergebnis2 + "\n" + "Menge: " + ergebnis3;
try {
ObjectOutputStream out;
out = new ObjectOutputStream(new FileOutputStream( "Bestellung.txt" ));
out.writeObject(s);
out.flush();
out.close();
} catch( IOException ex ) {
System.out.println( ex );
}
}
public void valueChanged(ListSelectionEvent event) {
//Indiies setzen:
int i = list.getSelectedIndex();
textfeld1.setText(ARTIKELNR[i]);
textfeld2.setText(PREIS[i]);
dateinamewahl = (BILD[i]);
//Image erzeugen
Toolkit tk = Toolkit.getDefaultToolkit();
ibild = tk.getImage(dateinamewahl);
//Bild neu geladen:
panel_bild.setAktBild(ibild);
repaint();
}
class MeinML extends MouseAdapter {
//Maus clicken:
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
int[] selektierte_indizes = list.getSelectedIndices();
for (int i =0; i< selektierte_indizes.length; i++)
System.out.println(BESCHREIBUNG[selektierte_indizes[i]]);
}
}
}
public static void main(String[] args){
Lebensmittel fenster = new Lebensmittel(null);
fenster.setLocation(100,100);
fenster.setSize(600,400);
fenster.setResizable(true);
fenster.setVisible(true);
}
}
To create your own collections, you must have a Mozilla Add-ons account.