tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
4
ZUGRIFFE
231
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Avatar von Nortia
    Nortia Nortia ist offline Grünschnabel
    Registriert seit
    Feb 2008
    Beiträge
    3
    Hallo,
    ich habe hier einen Entwurf einer Filmdatenbank und bis jetzt funktioniert es auch, aber jetzt will ich, dass die Bewertungen der Zuschauer (GUT,MITTEL und SCHLECHT) im Feld "Ergebnis" zu einer Durchschnittsnote ausgerechnet werden. Und das am besten gleich, wenn man auf den Button "einfügen" klickt.
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    
    package org.programm.table;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.ListSelectionEvent;
     
    public class Programm extends JFrame{
        private static final long serialVersionUID = 1L;
        int selectedrow = 0;
        int elementPosition = 0;
        Film a = new Film();    
        Film ZwischenAblage = new Film();
        Vector<Object> Tüber = new Vector<Object>();
        Vector<Film> daten = new Vector<Film>();
        Vector<Integer> indizes = new Vector<Integer>();
        boolean ExistiertDatei = false;
        String dateiname = new String();
        JMenuBar Menu = new JMenuBar();
        JMenu    Datei = new JMenu("Datei");
        JMenu    Bearbeiten = new JMenu("Bearbeiten");
        JMenu    Hilfe = new JMenu("Hilfe");
        JMenuItem neu = new JMenuItem("Neu",'N');
        JMenuItem offnen = new JMenuItem("Öffnen");
        JMenuItem speichern = new JMenuItem("Speichern");
        JMenuItem sunter = new JMenuItem("Speichern Unter");
        JMenuItem beenden = new JMenuItem("Beenden");
        JMenuItem einfügen = new JMenuItem("Einfügen");
        JMenuItem kopieren = new JMenuItem("Kopieren");
        JMenuItem ausschneiden = new JMenuItem("Ausschneiden");
        JMenuItem hilfe = new JMenuItem("Hilfe");
        JMenuItem info = new JMenuItem("Info");
        JFileChooser fileChooser = new JFileChooser();
        JPanel panel1 = new JPanel();
        JPanel panel2 = new JPanel();   
        JTabbedPane pane = new JTabbedPane();
        JTextField fdatum = new JTextField(11);
        JTextField fname = new JTextField(40);
        JTextField fgut = new JTextField(25);
        JTextField fschlecht = new JTextField(30);
        JTextField fmit = new JTextField(20);
        JTextField fges = new JTextField(15);
        JTextArea fsonstiges = new JTextArea(); 
        JLabel ldatum = new JLabel("Datum");
        JLabel lname = new JLabel("Name des Films");
        JLabel lgut = new JLabel("GUT" );  
                    JLabel lschlecht = new JLabel("SCHLECHT");
        JLabel lmit = new JLabel("MITTEL");
        JLabel lges = new JLabel("Gesamt");
        JLabel lsonstiges = new JLabel("Sonstiges");
        JLabel llogo = new JLabel(new ImageIcon("logo2.gif"));
        JScrollPane ssonstiges = new JScrollPane(); 
        JButton bvorwärts  = new JButton("Vorwärts");
        JButton bzurück    = new JButton("Zurück"); 
        JButton beinfügen  = new JButton("Einfügen");
        JButton blöschen   = new JButton("Löschen");
        JButton bsuchen    = new JButton("Suchen");
        JButton balles     = new JButton("Alles anzeigen");
        JButton bsortieren = new JButton("Sortieren");
        JButton bändern    = new JButton("Ändern"); 
        PersonInfoModel myModel = new PersonInfoModel();    
        JTable table = new JTable(myModel);     
        JScrollPane stabelle = new JScrollPane(table);
        JComboBox csuchen = new JComboBox();
        JComboBox csortieren = new JComboBox();
        JTextField fsuchen = new JTextField();  
        JButton b1suchen = new JButton("Suchen");
        JButton b1alles  = new JButton("Alles anzeigen");
        JButton b1sortieren = new JButton("Sortieren"); 
        JLabel  llogo2 = new JLabel(new ImageIcon("logo2.gif"));    
        private Vector temp;
        
        public static void main(String args[]) {            
            new Programm();
        }
        /**
         * Der Konstruktor                                                    
         */ 
        public Programm() {         
            initGUI();
        }       
        
            public void initGUI() {         
            this.setResizable(false);
            enableEvents(WindowEvent.WINDOW_CLOSING);
            this.setSize(new Dimension(600,440));
            this.setTitle("Filmdatenbank");         
            initMenu();
                                    initEdit();
            initList();
            pane.addTab("Listen Ansicht",panel1);
            pane.addTab("Editieren",panel2);
            this.getContentPane().add(pane);
            this.setVisible(true);
            getContentPane().setBackground(farbe2);
            pane.setBackground(farbe2);
        }   
                  
        Color farbe=new Color(220, 225, 255);
        Color farbe2=new Color(255, 255, 255);      
        
        public void initMenu() {        
            Datei.add(neu);
            neu.setMnemonic('N');
            Datei.addSeparator();
            Datei.add(offnen);
            Datei.addSeparator();
            offnen.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.Event.CTRL_MASK));
            Datei.add(speichern);
            speichern.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.Event.CTRL_MASK));
            Datei.addSeparator();
            Datei.add(sunter);
            Datei.addSeparator();
            Datei.add(beenden);
            beenden.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.Event.CTRL_MASK));     
            Bearbeiten.add(einfügen);
            einfügen.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.Event.CTRL_MASK));
            Bearbeiten.addSeparator();
            Bearbeiten.add(kopieren);
            kopieren.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.Event.CTRL_MASK));
            Bearbeiten.addSeparator();
            Bearbeiten.add(ausschneiden);
            ausschneiden.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.Event.CTRL_MASK));        
            Hilfe.add(info);
            Menu.add(Datei);
            Menu.add(Bearbeiten);
            Menu.add(Hilfe);
            Menu.setBackground(farbe);      
            neu.addActionListener(new MenuActionAdapter(this,1));
            offnen.addActionListener(new MenuActionAdapter(this,2));
            speichern.addActionListener(new MenuActionAdapter(this,3));
            sunter.addActionListener(new MenuActionAdapter(this,4));
            beenden.addActionListener(new MenuActionAdapter(this,5));   
            kopieren.addActionListener(new MenuActionAdapter(this,6));
            einfügen.addActionListener(new MenuActionAdapter(this,7));
            ausschneiden.addActionListener(new MenuActionAdapter(this,8));  
            info.addActionListener(new MenuActionAdapter(this,10)); 
            this.setJMenuBar(Menu);     
            }   
        
        public void initEdit() 
        {
            panel2.setLayout(null);     
            ldatum.setBounds(10,10,100,20);
            panel2.add(ldatum);
            fdatum.setBounds(110,10,250,20);
            panel2.add(fdatum);     
            lname.setBounds(10,40,100,20);
            panel2.add(lname);
            fname.setBounds(110,40,250,20);
            panel2.add(fname);      
            lgut.setBounds(10,70,100,20);
            panel2.add(lgut);
            fgut.setBounds(110,70,250,20);
            panel2.add(fgut);       
            lschlecht.setBounds(10,100,100,20);
            panel2.add(lschlecht);
            fschlecht.setBounds(110,100,250,20);
            panel2.add(fschlecht);      
            lmit.setBounds(10,130,100,20);
            panel2.add(lmit);
            fmit.setBounds(110,130,250,20);
            panel2.add(fmit);   
            lges.setBounds(10,160,100,20);
            panel2.add(lges);
            fges.setBounds(110,160,250,20);
            panel2.add(fges);
            lsonstiges.setBounds(10,210,100,20);
            panel2.add(lsonstiges);     
            fsonstiges.setLineWrap(true);
            ssonstiges.setBounds(110,210,250,100);
            ssonstiges.getViewport().add(fsonstiges);   
            panel2.add(ssonstiges);     
            bvorwärts.setBounds(370,10,100,50);
            bvorwärts.setMnemonic('v');
            panel2.add(bvorwärts);      
            bzurück.setBounds(480,10,100,50);
            bzurück.setMnemonic('z');
            panel2.add(bzurück);    
            beinfügen.setBounds(370,250,100,50);
            beinfügen.setMnemonic('e');
            panel2.add(beinfügen);  
            blöschen.setBounds(480,250,100,50);
            blöschen.setMnemonic('l');
            panel2.add(blöschen);
            bsuchen.setBounds(370,190,100,50);
            bsuchen.setMnemonic('s');
            panel2.add(bsuchen);
            balles.setBounds(370,310,210,40);
            balles.setMnemonic('a');
            panel2.add(balles);
            llogo.setBounds(370,70,210,110);
            panel2.add(llogo);  
            bändern.setBounds(480,190,100,50);
            bändern.setMnemonic('ä');
            panel2.add(bändern);    
            bvorwärts.addActionListener(new MenuActionAdapter(this,50));
            bzurück.addActionListener(new MenuActionAdapter(this,51));
            beinfügen.addActionListener(new MenuActionAdapter(this,52));
            blöschen.addActionListener(new MenuActionAdapter(this,53));
            bändern.addActionListener(new MenuActionAdapter(this,54));
            bsuchen.addActionListener(new MenuActionAdapter(this,55));
            balles.addActionListener(new MenuActionAdapter(this,56));   
            panel2.setBackground(farbe);
            csuchen.setBackground(farbe2);
            csortieren.setBackground(farbe2);       
        }   
        
        public void initList() {
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            
            ListSelectionModel rowSM = table.getSelectionModel();
            rowSM.addListSelectionListener(new ListSelectionListener() {    
                public void valueChanged(ListSelectionEvent e) {
                        if (e.getValueIsAdjusting()) return;        
                        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                        if (lsm.isSelectionEmpty()) 
                        {
                                }
                            else 
                                {
                                selectedrow = lsm.getMinSelectionIndex();
                            Integer temp = (Integer)indizes.get(selectedrow);
                            elementPosition = temp.intValue();
                            setElement();   
                        }
                    }
            });
     
            table.setAutoResizeMode(JTable. AUTO_RESIZE_OFF);
            panel1.setLayout(null);
            stabelle.setBounds(10,10,350,340);
            panel1.add(stabelle);
            panel1.setBackground(farbe);        
            item(csuchen);
            csuchen.setBounds(370,10,210,20);
            panel1.add(csuchen);        
            fsuchen.setBounds(370,40,210,20);
            panel1.add(fsuchen);    
            b1suchen.setBounds(370,70,210,20);
            b1suchen.setMnemonic('u');
            panel1.add(b1suchen);
            b1alles.setBounds(370,100,210,20);
            b1alles.setMnemonic('a');
            panel1.add(b1alles);
            b1sortieren.setBounds(370,330,210,20);
            b1sortieren.setMnemonic('o');
            panel1.add(b1sortieren);
            item(csortieren);
            csortieren.setBounds(370,300,210,20);
            panel1.add(csortieren);
            llogo2.setBounds(370,130,210,160);
            panel1.add(llogo2);
            b1alles.addActionListener(new MenuActionAdapter(this,56));
            b1sortieren.addActionListener(new MenuActionAdapter(this,61));
            b1suchen.addActionListener(new MenuActionAdapter(this,60));
        }
        
        void item(JComboBox temp){
            temp.addItem("Datum");
            temp.addItem("Name des Films");
            temp.addItem("GUT");
            temp.addItem("SCHLECHT");
            temp.addItem("MITTEL");
            temp.addItem("Gesamt");
            temp.setBounds(10,10,210,20);
        }
     
        void menuEvent(ActionEvent e, int event_id) 
        {
            switch(event_id)
            {
                case  1: m_neu();break; 
                case  2: m_öffnen();break;
                case  3: m_speichern();break;
                case  4: m_sunter();break;
                case  5: m_beenden();break; 
                case  6: m_kopieren();break;
                case  7: m_einfügen();break;
                case  8: m_ausschneiden();break;
                case 10: m_info();break;
                case 50: b_vor();break;
                case 51: b_zurück();break;
                case 52: b_einfügen();break;
                case 53: b_löschen();break;
                case 54: b_ändern();break;
                case 55: b_suchen();break;
                case 56: b_alles();break;
                case 60 : b1_suchen();break;
                case 61 : sortieren();break;
            }
        }   
        public void m_info()
        {
            System.out.println("TEST");
            
            JDialog idialog = new JDialog(this, "INFO", true);
            JLabel ilogo = new JLabel(new ImageIcon("logo2.gif"));
            JLabel iversion = new JLabel("Version 1.0");
            JLabel ivon     = new JLabel("Von :");
            JLabel ikk    = new JLabel("K. K.,");
            JLabel iemail  = new JLabel("-------@yahoo.de");        
            JLabel iinfo1   = new JLabel("Wenn Sie Fragen oder");
            JLabel iinfo2   = new JLabel("Anwendungsprobleme haben,");
            JLabel iinfo3   = new JLabel("dann wenden Sie sich an die oben genannte");
            JLabel iinfo4   = new JLabel("E-Mail-Adresse.");         
            JPanel ipanel = new JPanel();       
            ipanel.setLayout(null);
            ilogo.setBounds(20,20,250,100);
            ipanel.add(ilogo);
            iversion.setBounds(20,100,220,20);
            ipanel.add(iversion);
            ivon.setBounds(20,130,220,20);
            ipanel.add(ivon);
            ikk.setBounds(20,170,220,20);
            ipanel.add(ikk);
            iemail.setBounds(20,190,220,20);
            ipanel.add(iemail);
            iinfo1.setBounds(20,210,250,20);
            ipanel.add(iinfo1);
            iinfo2.setBounds(20,230,250,20);
            ipanel.add(iinfo2);
            iinfo3.setBounds(20,250,250,20);
            ipanel.add(iinfo3);
            iinfo4.setBounds(20,270,250,20);
            ipanel.add(iinfo4);
            idialog.getContentPane().add(ipanel);
            idialog.setSize(290,350);
            this.setResizable(false);
            idialog.setVisible(true);       
        }
        
        public void b_suchen()
        {
            Film temp = new Film();
            temp.Datum = fdatum.getText();
            temp.Name = fname.getText();
            temp.Gut = fgut.getText();
            temp.Schlecht = fschlecht.getText();
            temp.Mit = fmit.getText();
            temp.Ges = fges.getText();
            temp.Sonstiges = fsonstiges.getText();  
            
            if(temp.Datum.length() > 0) 
            {
                suchen(0,temp.Datum);   
            }
            if(temp.Name.length() > 0) 
            {
                suchen(1,temp.Name);
            }
            if(temp.Gut.length() > 0)
            {
                suchen(2,temp.Gut);
            }
            if(temp.Schlecht.length() > 0)
            {
                suchen(3,temp.Schlecht);
            }
            if(temp.Mit.length() > 0)
            {
                suchen(4,temp.Mit);
            }
            if(temp.Ges.length() > 0)
            {
                suchen(5,temp.Ges);
            }
            if(temp.Datum.length() > 0)
            {
                suchen(1,temp.Name);
            }
            if(temp.Datum.length() > 0)
            {
                suchen(2,temp.Ges);
            }
        }
      
        public void b1_suchen()
        {
            int krit = csuchen.getSelectedIndex();
            String zus = fsuchen.getText();
            suchen(krit,zus);   
        }
        
        public void suchen(int krit,String zusuchen)
        {
            Vector<Integer> temp = new Vector<Integer>();
            Integer itemp = new Integer(0);
            Film ptemp = new Film();
            for(int i = 0; i < indizes.size();i++)
            {
                itemp = (Integer)indizes.get(i);
                ptemp = (Film)daten.get(itemp.intValue());
                if(ptemp.Vergleiche(krit,ptemp,zusuchen) == 0)
                {
                    temp.add(itemp);
                }
            }
            if(temp.isEmpty() == false)
            {
                indizes = temp;
                selectedrow = 0;
                itemp = (Integer)indizes.get(selectedrow);
                    elementPosition = itemp.intValue();
                table.setRowSelectionInterval(selectedrow,selectedrow);
                setElement();
            }
            TabelAkt();
        }  
     
        public void sortieren()
        {
            int krit = csortieren.getSelectedIndex();
            int laenge = indizes.size();
            
            Integer temp1 = new Integer(0);
            Integer temp2 = new Integer(0);
            Film ptemp1;
            Film ptemp2;
            int status;
            boolean nichtsort = true;
            while((nichtsort == true) && (laenge > 1) )
            {
                laenge--;
                nichtsort = false;
     
                for(int i = 0; i<laenge;i++)
                {
                    temp1 = (Integer)indizes.get(i);
                    temp2 = (Integer)indizes.get(i+1);
                    ptemp1 = (Film)daten.get(temp1.intValue());
                    ptemp2 =(Film)daten.get(temp2.intValue());
                    status = ptemp1.Vergleiche(krit,ptemp1,ptemp2); 
                    if(status == 1)
                    {
                        indizes.setElementAt(temp2,i);
                        indizes.setElementAt(temp1,i+1);
                        nichtsort = true;
                    }
                    if(status == 0)
                    {
                        for(int in = 0;in<8;in++)
                        {
                            if(in != krit)
                            {
                                status = ptemp1.Vergleiche(in,ptemp1,ptemp2);       
                                if(status == 1)
                                {
                                    indizes.setElementAt(temp2,i);
                                    indizes.setElementAt(temp1,i+1);    
                                    in = 8;
                                    nichtsort = true;
                                }
                            }
                        }
                    }
                }
            }
            TabelAkt(); 
        }
        
        public void b_alles()
        {
            indizes.clear();
            Integer temp = new Integer(0);
            for(int i = 0;i<daten.size();i++)
            {
                temp = new Integer(i);
                indizes.add(temp);
            }
            TabelAkt();
        }
        
        public void m_kopieren()
        {
            Film temp = (Film)daten.get(elementPosition);
            temp.Datum = fdatum.getText();
            temp.Name = fname.getText();
            temp.Gut = fgut.getText();
            temp.Schlecht = fschlecht.getText();
            temp.Mit = fmit.getText();
            temp.Ges = fges.getText();
            temp.Sonstiges = fsonstiges.getText();  
            ZwischenAblage = temp;
        }
        
        public void m_einfügen()
        {
            Film temp = ZwischenAblage;
            fdatum.setText(temp.Datum);
            fname.setText(temp.Name);
            fgut.setText(temp.Gut);
            fschlecht.setText(temp.Schlecht);
            fmit.setText(temp.Mit);
            fges.setText(temp.Ges);
            fsonstiges.setText(temp.Sonstiges);
            b_einfügen();
            sortieren();
        }       
        
        public void m_ausschneiden()
        {
            if(indizes.isEmpty() == false)
            {
                ZwischenAblage =(Film)daten.get(elementPosition);
                b_löschen();
            }
        }   
      
         public void b_ändern()
        {
            Film temp = new Film();
            temp.Datum = fdatum.getText();
            temp.Name = fname.getText();
            temp.Gut = fgut.getText();
            temp.Schlecht = fschlecht.getText();
            temp.Mit = fmit.getText();
            temp.Ges = fges.getText();
            temp.Sonstiges = fsonstiges.getText();  
            daten.setElementAt(temp,elementPosition);
            sortieren();
        }   
      
        public void b_löschen()
        {
            if(indizes.isEmpty() == false)
            {
                indizes.removeElementAt(selectedrow);
                daten.removeElementAt(elementPosition);
                Integer temp = new Integer(0);
                for(int i = 0; i < indizes.size();i++)
                {
                    temp = (Integer)indizes.get(i);
                    if(temp.intValue()>elementPosition)
                    {
                        temp = new Integer(temp.intValue()-1);
                        indizes.setElementAt(temp,i);
                    }
                }
                if(indizes.isEmpty() == false)
                {
                    if(selectedrow >= indizes.size())
                    {
                        selectedrow = indizes.size()-1;
                        temp = (Integer)indizes.get(selectedrow);
                            elementPosition = temp.intValue();  
                    }
                    if(selectedrow < 0)
                    {
                        selectedrow = 0;
                        temp = (Integer)indizes.get(selectedrow);
                            elementPosition = temp.intValue();  
                    }
                    table.setRowSelectionInterval(selectedrow,selectedrow);
                    TabelAkt();
                }
                else 
                {
                    daten.clear();
                    indizes.clear();
                    TabelAkt();
                }
            }
        }   
      
         public void b_vor()
        {
            if(selectedrow<(indizes.size()-1))
            {
                selectedrow++;
                Integer temp = (Integer)indizes.get(selectedrow);
                    elementPosition = temp.intValue();
                setElement();
                table.setRowSelectionInterval(selectedrow,selectedrow);
            }
        }   
      
        public void b_zurück()
        {
            if(selectedrow>0)
            {
                selectedrow--;
                Integer temp = (Integer)indizes.get(selectedrow);
                    elementPosition = temp.intValue();
                setElement();
                table.setRowSelectionInterval(selectedrow,selectedrow);
                }
            }   
     
        protected void processWindowEvent(WindowEvent evt)
        {
            if(evt.getID() == WindowEvent.WINDOW_CLOSING) 
            {
                System.exit(0);
            }
        }   
        
        public void m_neu()
        {
            String msg=new String("Es können nichtgespeicherte Dateien verloren gehen." +
            "\nMöchten Sie ein neues Projekt beginnen?");
            int returnVal=JOptionPane.showConfirmDialog(b1alles,msg,"Beenden",
                    JOptionPane.YES_NO_OPTION);
            if(returnVal == JOptionPane.YES_OPTION){
            temp = new Vector<Object>();
            daten.clear();
            indizes.clear();
            ExistiertDatei = false;
            dateiname = null;
            fileChooser = new JFileChooser();
            
            TabelAkt();
            }
        }   
     
        public void m_öffnen() 
        {
            int retval = fileChooser.showDialog(this,"Projekt Öffnen");
            if(retval == JFileChooser.APPROVE_OPTION)
            {
                dateiname = fileChooser.getSelectedFile().getPath();
        
                ladeListe(dateiname);
                ExistiertDatei = true;
                indizes.clear();
                
                Integer temp = new Integer(0);
                for(int i = 0;i<daten.size();i++)
                {
                    temp = new Integer(i);
                    indizes.add(temp);
                }
                sortieren();
            }
        }   
     
        public void m_speichern()
        {
            if(ExistiertDatei == true)
            {
                saveListe(dateiname);
            }
            if(ExistiertDatei == false)
            {
                m_sunter();
            }
        }   
     
        public void m_sunter()
        {
            int retval = fileChooser.showDialog(this,"Projekt Speichern");
            if(retval == JFileChooser.APPROVE_OPTION)
            {
                dateiname = fileChooser.getSelectedFile().getPath();
                saveListe(dateiname);
                ExistiertDatei = true;
            }
        }   
     
        public void b_einfügen()
        {
            Film temp = new Film();
            temp.Datum = fdatum.getText();
            temp.Name = fname.getText();
            temp.Gut = fgut.getText();
            temp.Schlecht = fschlecht.getText();
            temp.Mit = fmit.getText();
            temp.Ges = fges.getText();
            temp.Sonstiges = fsonstiges.getText();
            //temp.Ergebnis = ?
            
            
            
            daten.add(temp);
            indizes.add(new Integer(daten.size()-1));
            sortieren();
        }   
     
        public void m_beenden()
        {
            
            String msg=new String("Das Programm wird auch beendet, falls Sie nicht gespeichert haben. " +
                    "\nMöchten Sie das Programm beenden?");
              int returnVal=JOptionPane.showConfirmDialog(b1alles,msg,"Beenden",JOptionPane.YES_NO_OPTION);
              if(returnVal == JOptionPane.YES_OPTION){
              System.exit(0);
              }
        }   
     
        public void saveListe(String dname) 
        {
            try 
            {
                File f = new File(dname);
                FileOutputStream fos = new FileOutputStream(f);
                ObjectOutputStream oos = new ObjectOutputStream(fos);
                oos.writeObject(daten);
                oos.flush();
                fos.close();        
            }
            catch(IOException e) 
            {
                System.out.println("Fehler beim Laden");
            }
        }   
        
        public void ladeListe(String dname) 
        {
            try 
            {   
                File f = new File(dname);
                FileInputStream fis = new FileInputStream(f);
                InputStreamReader isr = new InputStreamReader(fis);
                ObjectInputStream ois = new ObjectInputStream(fis);
                    
                try 
                {
                    daten = (Vector)ois.readObject();
                }
                catch ( java.lang.ClassNotFoundException cnfe)
                {
                    System.out.println("Einlesen Gescheitert");
                };
            
                fis.close();
            }
            catch(IOException e) 
            {
                System.out.println("Fehler beim Laden");
            }
        }   
        
        public void TabelAkt()
        {
            myModel.clear();
            Integer index = new Integer(0);
            for(int i = 0; i < indizes.size();i++)
            {
                index = (Integer)indizes.get(i);
                myModel.updatePerson((Film)daten.get(index.intValue()));
            }       
            table.repaint();        
        }   
     
        public void setElement()
        {
            Film temp = (Film)daten.get(elementPosition);
            fdatum.setText(temp.Datum);
            fname.setText(temp.Name);
            fgut.setText(temp.Gut);
            fschlecht.setText(temp.Schlecht);
            fmit.setText(temp.Mit);
            fges.setText(temp.Ges);
            fsonstiges.setText(temp.Sonstiges);     
        }
    }
     
    class MenuActionAdapter implements ActionListener {
        
        Programm obj;
        int event_id;
     
        MenuActionAdapter(Programm obj,int event_id) {
                
            this.obj = obj;
            this.event_id = event_id;
        }
     
        public void actionPerformed(ActionEvent e)  {
                
            obj.menuEvent(e,event_id);
        }
    }
     
    class PersonInfoModel extends AbstractTableModel {
        private static final long serialVersionUID = 1L;
            protected static int NUM_COLUMNS = 8;
            protected static int START_NUM_ROWS = 0;
            protected int nextEmptyRow = 0;
            protected int numRows = 0;
     
            static final public String Datum = "Datum";
            static final public String Name = "Name des Films";
            static final public String Gut = "GUT";
            static final public String Schlecht = "SCHLECHT";
            static final public String Mit = "MITTEL";
            static final public String Ges = "Gesamt";
            static final public String Sonstiges = "Sonstiges";
            static final public String Ergebnis = "Ergebnis";
        
            protected Vector<Film> data = null;
     
            public PersonInfoModel() 
            {
                data = new Vector<Film>();
            }
     
            public String getColumnName(int column) 
            {
                switch (column) 
                {
                case 0: return Datum;
                case 1: return Name;
                case 2: return Gut;
                case 3: return Schlecht;
                case 4: return Mit;
                case 5: return Ges;
                case 6: return Sonstiges;
                case 7: return Ergebnis;
                
            }
                
            return "";
            }       
     
            public synchronized int getColumnCount() 
            {
                return NUM_COLUMNS;
            }
     
            public synchronized int getRowCount() 
            {
                if (numRows < START_NUM_ROWS)
                {
                        return START_NUM_ROWS;
                }
                else 
                {
                        return numRows;
                }
            }
     
            public synchronized Object getValueAt(int row, int column) 
            {
            try 
            {
                Film p = (Film)data.elementAt(row);
                        switch (column) 
                        {
                    
                        case 0: return new String(p.Datum);
                        case 1: return new String(p.Name);
                        case 2: return new String(p.Gut);
                        case 3: return new String(p.Schlecht);
                        case 4: return new String(p.Mit);
                        case 5: return new String(p.Ges);
                        case 6: return new String(p.Sonstiges);
                        case 7: return new String(p.Ergebnis);
                }
            }
            catch (Exception e) 
            {
            }
            return "";
            }
     
            public synchronized void updatePerson(Film p) 
            {
            
                int index = -1; 
                boolean addedRow = false;
            
           
                if (numRows <= nextEmptyRow) 
                {
                    numRows++;
                addedRow = true;
                }
                index = nextEmptyRow;
            data.addElement(p);
            
                nextEmptyRow++;
     
            if (addedRow) 
            {
                    fireTableRowsInserted(index, index);
            } 
            else 
            {
                fireTableRowsUpdated(index, index);
                }
            }
     
            public synchronized void clear() 
            {
            int oldNumRows = numRows;
     
                numRows = START_NUM_ROWS;
            data.removeAllElements();
                nextEmptyRow = 0;
     
            if (oldNumRows > START_NUM_ROWS)
            {
                    fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
            }
            fireTableRowsUpdated(0, START_NUM_ROWS - 1);
            }
    }
     
    class Film implements Serializable 
    {
     
        private static final long serialVersionUID = 1L;
        
        String Datum = new String();
        String Name = new String();
        String Gut = new String();
        String Schlecht = new String();
        String Mit = new String();
        String Ges = new String();
        String Sonstiges = new String();
        String Ergebnis = new String();
        
        
        public Film(){
        }
        
     
        public int Vergleiche(int k,Film a,Film b)
        {
            switch(k)
            {
                case 0: return V_String(a.Datum,b.Datum);
                case 1: return V_String(a.Name,b.Name);
                case 2: return V_String(a.Gut,b.Gut);
                case 3: return V_String(a.Schlecht,b.Schlecht);
                case 4: return V_String(a.Mit,b.Mit);
                case 5: return V_String(a.Ges,b.Ges);
                case 7: return V_String(a.Ergebnis,b.Ergebnis);
            }
            return 3;
        }
        public int Vergleiche(int k,Film a,String b)
        {
            switch(k)
            {
                case 0: return V_Strings(a.Datum,b);
                case 1: return V_Strings(a.Name,b);
                case 2: return V_Strings(a.Gut,b);
                case 3: return V_Strings(a.Schlecht,b);
                case 4: return V_Strings(a.Mit,b);
                case 5: return V_Strings(a.Ges,b);
            }
            return 3;
        }   
     
        public int V_String(String a , String b)
        {
            int temp = a.compareTo(b);
            if(temp == 0) return 0;
            if(temp <  0) return -1;
            if(temp >  0) return 1;
            return 3;
        }   
     
        public int V_Strings(String a,String b)
        {
            boolean temp = a.startsWith(b);
            if(temp == true) return 0;
            return 3;
        }   
    }
    Vielleicht kann mir ja jemand einen Tipp geben, wie ich den Algorithmus einbinde, denn im Moment stehe ich auf dem Schlauch.
    Thx schonmal
    Nortia
     

  2. #2
    kaMii Tutorials.de Gastzugang
    Hi,

    an deiner Stelle würde ich für die Bewertung nur eine Spalte machen und eine Auswahlbox mit 3 Werten (Gut (1), Mittel(2) und Schlecht (3)) zur Verfügung stellen.
    Je nachdem wann du das ganze Berrechnen willst musst du dir eben einen entsprechenden Listener setzen. Wenn du es beim "Einfügen"-button haben willst musst du dem Button eben einen Listener hinzufügen.
    Die Bewertungen für die verschiedenen Filme kannst du dann ja ganz locker im handler zusammenzählen, und durch die Anzahl teilen dann noch auf oder abrunden und du hast deine Bewertung.

    Ich rate dir auch das ganze nicht in einer Klasse unter zu bringen sondern ein bisschen aufzuspalten. Wenn du ein paar Getter und Setter hinzufügst ist das sofort gemacht.

    Gruss

    Ben
     

  3. #3
    Chimaira Chimaira ist offline Mitglied Gold
    Registriert seit
    May 2005
    Beiträge
    143
    Hoi,

    alter Schwede, das ist mal ne Klasse .... extrahier mal die Funktionalität in ne andere Klasse . Du hast Geschäftslogik und GUI in eine Klasse gehauen *auf die finger hau*

    Greeze Chimaira
     

  4. #4
    Avatar von Nortia
    Nortia Nortia ist offline Grünschnabel
    Registriert seit
    Feb 2008
    Beiträge
    3
    *g*
    ja übersichtlich isses nich mehr.
    Ich dank euch für die schnelle Antwort, werde jetzt noch ein wenig basteln und versuchen, einen Stil hineinzubringen.
    Nortia
     

  5. #5
    Avatar von Nortia
    Nortia Nortia ist offline Grünschnabel
    Registriert seit
    Feb 2008
    Beiträge
    3
    Habe das Problem jetzt mit nem extra Button und nem ActionListener gelöst:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    bberechnen.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            Berechnen( new Integer( fgut.getText()).intValue() ,
                                    new Integer( fschlecht.getText()).intValue(),
                                    new Integer(fmit.getText()).intValue(),
            new Integer(fges.getText()).intValue());
        }
    });
     
    public void Berechnen(double x, double y, double z, double q){
        double a;
        if(q!=(x+y+z)){
            String msg=new String("Die Gesamtanzahl ist fehlerhaft.");
            JOptionPane.showMessageDialog(b1alles,msg,"Berechnen",
            JOptionPane.INFORMATION_MESSAGE);
        }
        if(q!=0 && q==(x+y+z)){ 
            a=((x*1)+(y*6)+(z*3))/q;
            fergebnis.setText(String.valueOf(a));
        }   
    }

    Das ist zwar total simple, aber erfüllt seinen Zweck.
    Ach ja, habe es ein wenig aufgesplittet, aber das muss ich ja nich nochmal posten. *grins*
    Hat jemand ne Idee, wie man dem Programm für das "sortieren" klar machen kann, dass10 größer ist als 2.
    Bisher, schaut es sich nämlich nur die erste Ziffer an. Es ginge sicherlich, wenn man statt "2" eben "02" eingibt, aber da gibts doch bestimmt noch ne andere Möglichkeit.

    Thx schonmal
    Nortia
     

Ähnliche Themen

  1. Antworten: 5
    Letzter Beitrag: 02.06.10, 12:52
  2. Antworten: 1
    Letzter Beitrag: 02.07.07, 21:31
  3. Abfrage einer spalte von einer anderen tabelle
    Von bcallifornia im Forum Relationale Datenbanksysteme
    Antworten: 1
    Letzter Beitrag: 02.11.05, 19:06
  4. Antworten: 8
    Letzter Beitrag: 28.10.05, 22:08
  5. Inhalt aller Felder einer Spalte aus einer Tabelle rauslesen
    Von messmar im Forum Relationale Datenbanksysteme
    Antworten: 3
    Letzter Beitrag: 12.01.05, 15:17