Tabelle Zeilen kopieren < Java < Programmiersprachen < Praxis < Informatik < Vorhilfe
|
Status: |
(Frage) überfällig | Datum: | 15:18 Sa 08.01.2011 | Autor: | Fatih17 |
Aufgabe | In einem Dialogfenster soll man Klausuren selektieren können und zu jeder Klausur Studenten hinzufügen können.
In einem anderen Dialogfenster soll man beim selektieren der Klausuren die Studenten sehen können, die hinzugefügt wurden. |
Guten Tag,
ich habe zunächst zwei ArrayList erstellt in der Klasse Prufungsamt indem Klausur und Studentenobjekte enthalten sind.
Dann habe ich zwei Klassen erstellt "Klausuranmelden" und "Anmeldeliste" und es geschafft, dass die ArrayLists in Tabellen ausgegeben werden.
Weiter bin ich dann leider nicht gekommen.
Hier die Klasse Klausuranmelden:
[CODE]
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Klausuranmelden extends AbstractTableModel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JDialog kan;
private JLabel label1;
private JScrollPane scrollPane1;
private JLabel label2;
private JScrollPane scrollPane2;
private JButton button1;
private JButton button2;
JTable table2 = new JTable(new AbstractTableModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getColumnName(int column) {
switch (column) {
case 0:
return "Universität";
case 1:
return "Vorname";
case 2:
return "Nachname";
case 3:
return "Matrikelnummer";
case 4 :
return "Studiengang";
}
return "";
}
public Object getValueAt(int row, int column) {
Student student = Prufungsamt.students.get(row);
switch (column) {
case 0:
return student.getuni();
case 1:
return student.getvorname();
case 2:
return student.getnachname();
case 3:
return student.getmatrikelnummer();
case 4:
return student.getstudiengang();
}
return null;
}
public int getColumnCount() {
return 5;
}
public int getRowCount() {
return Prufungsamt.students.size();
}
});
JTable table1 = new JTable(new AbstractTableModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getColumnName(int column) {
switch (column) {
case 0:
return "Datum";
case 1:
return "Uhrzeit";
case 2:
return "Raum";
case 3:
return "Dauer";
}
return "";
}
public Object getValueAt(int row, int column) {
Klausur klausur = Prufungsamt.klausuren.get(row);
switch (column) {
case 0:
return klausur.getDatum();
case 1:
return klausur.getUhrzeit();
case 2:
return klausur.getraum();
case 3:
return klausur.getdauer();
}
return null;
}
public int getColumnCount() {
return 4;
}
public int getRowCount() {
return Prufungsamt.klausuren.size();
}
});
JTable table3;
public void klausuranmelden() {
kan = new JDialog(Prufungsamt.frame,"Klausuranmeldung");
label1 = new JLabel();
scrollPane1 = new JScrollPane();
label2 = new JLabel();
scrollPane2 = new JScrollPane();
button1 = new JButton();
button2 = new JButton();
// Hauptmenu hm=new Hauptmenu();
// Container cp = hm.cp;
Dimension frameSize = new Dimension(690,550);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int top = (screenSize.height - frameSize.height) / 2;
int left = (screenSize.width - frameSize.width) / 2;
kan.setSize(frameSize);
kan.setLocation(left,top);
kan.setLayout(null);
//---- label1 ----
label1.setText("Klausuren:");
kan.add(label1);
label1.setBounds(new Rectangle(new Point(300, 20), label1.getPreferredSize()));
//======== scrollPane1 ========
{
scrollPane1.setViewportView(table1);
}
kan.add(scrollPane1);
scrollPane1.setBounds(40, 55, 590, 145);
//---- label2 ----
label2.setText("Studenten:");
kan.add(label2);
label2.setBounds(new Rectangle(new Point(300, 220), label2.getPreferredSize()));
//======== scrollPane2 ========
{
scrollPane2.setViewportView(table2);
}
kan.add(scrollPane2);
scrollPane2.setBounds(40, 260, 590, 145);
//---- button1 ----
button1.setText("Anmelden");
button1.addActionListener(this);
kan.add(button1);
button1.setBounds(215, 440, 100, button1.getPreferredSize().height);
//---- button2 ----
button2.setText("Abbrechen");
kan.add(button2);
button2.setBounds(360, 440, 100, 26);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < kan.getComponentCount(); i++) {
Rectangle bounds = kan.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = kan.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
kan.setMinimumSize(preferredSize);
kan.setPreferredSize(preferredSize);
}
kan.validate();
kan.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Abbrechen")){
String option[] = { "Ja", "Nein" };
int n = JOptionPane.showOptionDialog( null,
"Wirklich Abbrechen?", // Fragetext
"Beenden", // Titel
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, // Icon
null, option,option[0]);
if ( n == JOptionPane.YES_OPTION ){
kan.dispose();
}
}
if (e.getActionCommand().equals("Anmelden")){
final int selectedRow;
Klausuranmelden nm= new Klausuranmelden();
AbstractTableModel model = (AbstractTableModel)table1.getModel();
selectedRow = table1.getSelectedRow();
if (selectedRow >= 0) {
String option[] = { "Ja", "Nein" };
int n = JOptionPane.showOptionDialog( null,
"Sind Sie sicher?", // Fragetext
"Beenden", // Titel
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, // Icon
null, option,option[0]);
if ( n == JOptionPane.YES_OPTION ){
//hier soll das hinzufügen zu einer anderen Tabelle hin
}
}
}
}
}
[/CODE]
Hier die Klasse "Anmeldeliste"
[CODE]
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
public class Anmeldeliste {
JDialog kan;
private JLabel label1;
private JScrollPane scrollPane1;
private JLabel label2;
private JScrollPane scrollPane2;
private JButton button1;
private JButton button2;
JTable table2 = new JTable(new AbstractTableModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getColumnName(int column) {
switch (column) {
case 0:
return "Universität";
case 1:
return "Vorname";
case 2:
return "Nachname";
case 3:
return "Matrikelnummer";
case 4 :
return "Studiengang";
}
return "";
}
public Object getValueAt(int row, int column) {
Student student = Prufungsamt.students.get(row);
switch (column) {
case 0:
return student.getuni();
case 1:
return student.getvorname();
case 2:
return student.getnachname();
case 3:
return student.getmatrikelnummer();
case 4:
return student.getstudiengang();
}
return null;
}
public int getColumnCount() {
return 5;
}
public int getRowCount() {
return Prufungsamt.students.size();
}
});
JTable table1 = new JTable(new AbstractTableModel() {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getColumnName(int column) {
switch (column) {
case 0:
return "Datum";
case 1:
return "Uhrzeit";
case 2:
return "Raum";
case 3:
return "Dauer";
}
return "";
}
public Object getValueAt(int row, int column) {
Klausur klausur = Prufungsamt.klausuren.get(row);
switch (column) {
case 0:
return klausur.getDatum();
case 1:
return klausur.getUhrzeit();
case 2:
return klausur.getraum();
case 3:
return klausur.getdauer();
}
return null;
}
public int getColumnCount() {
return 4;
}
public int getRowCount() {
return Prufungsamt.klausuren.size();
}
});
public void anmeldeliste() {
kan = new JDialog(Prufungsamt.frame,"Anmeldeliste");
label1 = new JLabel();
scrollPane1 = new JScrollPane();
label2 = new JLabel();
scrollPane2 = new JScrollPane();
button1 = new JButton();
button2 = new JButton();
Dimension frameSize = new Dimension(690,550);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int top = (screenSize.height - frameSize.height) / 2;
int left = (screenSize.width - frameSize.width) / 2;
kan.setSize(frameSize);
kan.setLocation(left,top);
kan.setLayout(null);
//---- label1 ----
label1.setText("Klausuren:");
kan.add(label1);
label1.setBounds(new Rectangle(new Point(300, 20), label1.getPreferredSize()));
//======== scrollPane1 ========
Klausuranmelden tn=new Klausuranmelden();
{
scrollPane1.setViewportView(tn.table3);
}
kan.add(scrollPane1);
scrollPane1.setBounds(40, 55, 590, 145);
//---- label2 ----
label2.setText("Studenten:");
kan.add(label2);
label2.setBounds(new Rectangle(new Point(300, 220), label2.getPreferredSize()));
//======== scrollPane2 ========
{
scrollPane2.setViewportView(table2);
}
kan.add(scrollPane2);
scrollPane2.setBounds(40, 260, 590, 145);
//---- button1 ----
button1.setText("OK");
kan.add(button1);
button1.setBounds(215, 440, 100, button1.getPreferredSize().height);
//---- button2 ----
button2.setText("Abbrechen");
kan.add(button2);
button2.setBounds(360, 440, 100, 26);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < kan.getComponentCount(); i++) {
Rectangle bounds = kan.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = kan.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
kan.setMinimumSize(preferredSize);
kan.setPreferredSize(preferredSize);
}
kan.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Abbrechen")){
String option[] = { "Ja", "Nein" };
int n = JOptionPane.showOptionDialog( null,
"Wirklich Abbrechen?", // Fragetext
"Beenden", // Titel
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, // Icon
null, option,option[0]);
if ( n == JOptionPane.YES_OPTION )
kan.dispose();
}
if (e.getActionCommand().equals("OK")){
kan.dispose();
}
}
}
[/CODE]
Vielen Dank im Voraus
MFG
Fatih
|
|
|
|
Status: |
(Mitteilung) Reaktion unnötig | Datum: | 15:30 Mo 10.01.2011 | Autor: | matux |
$MATUXTEXT(ueberfaellige_frage)
|
|
|
|