Last active
December 18, 2015 23:08
-
-
Save Ichag/5858928 to your computer and use it in GitHub Desktop.
Laender und Staedte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author max | |
*/ | |
import java.util.ArrayList; | |
public class Bundesland extends Land { | |
public Bundesland(String name) { | |
super(name); | |
} | |
@Override | |
public int compareTo(Land vergleichsLand) { | |
return this.getName().compareTo(vergleichsLand.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author max | |
*/ | |
import java.util.*; | |
public class DAO { | |
List<Land> laender = new ArrayList<Land>(); | |
/** | |
* @param args | |
*/ | |
public DAO() { | |
Land nrw = new Bundesland("Nordrhein-Westfalen"); | |
Land he = new Bundesland("Hessen"); | |
Stadt f = new Stadt("Frankfurt", false); | |
Stadt wi = new Stadt("Wiesbaden", true); | |
Stadt d = new Stadt("Duesseldorf", true); | |
Stadt bi = new Stadt("Bielefeld", false); | |
laender.add(nrw); | |
laender.add(he); | |
} | |
public List<Land> getLaender() { | |
return laender; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author max | |
*/ | |
public class GUI extends javax.swing.JFrame { | |
/** | |
* Creates new form GUI | |
*/ | |
public GUI() { | |
initComponents(); | |
} | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
jButton1 = new javax.swing.JButton(); | |
jScrollPane2 = new javax.swing.JScrollPane(); | |
jTextArea1 = new javax.swing.JTextArea(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
jButton1.setText("Städte anzeigen"); | |
jButton1.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jButton1ActionPerformed(evt); | |
} | |
}); | |
jTextArea1.setColumns(20); | |
jTextArea1.setRows(5); | |
jScrollPane2.setViewportView(jTextArea1); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addGap(33, 33, 33) | |
.addComponent(jButton1) | |
.addContainerGap(15, Short.MAX_VALUE)) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addContainerGap() | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) | |
.addComponent(jButton1)) | |
.addContainerGap(176, Short.MAX_VALUE)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
java.util.List<Land> laender = this.dao.getContries(); | |
for (Land land: laender) | |
{ | |
jTextArea1.append(land + "\n"); | |
} | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new GUI().setVisible(true); | |
} | |
}); | |
} | |
private Transfer dao = new Transfer(); | |
// Variables declaration - do not modify | |
private javax.swing.JButton jButton1; | |
private javax.swing.JScrollPane jScrollPane2; | |
private javax.swing.JTextArea jTextArea1; | |
// End of variables declaration | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
import javax.swing.event.*; | |
/** | |
* | |
* Beschreibung | |
* | |
* @version 1.0 vom 25.06.2013 | |
* @author | |
*/ | |
public class gui2 extends JFrame { | |
// Anfang Attribute | |
private JTextArea jTextArea1 = new JTextArea(""); | |
private JScrollPane jTextArea1ScrollPane = new JScrollPane(jTextArea1); | |
private JButton jButton1 = new JButton(); | |
private DAO myDao = new DAO(); | |
// Ende Attribute | |
public gui2(String title) { | |
// Frame-Initialisierung | |
super(title); | |
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | |
int frameWidth = 300; | |
int frameHeight = 300; | |
setSize(frameWidth, frameHeight); | |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); | |
int x = (d.width - getSize().width) / 2; | |
int y = (d.height - getSize().height) / 2; | |
setLocation(x, y); | |
setResizable(false); | |
Container cp = getContentPane(); | |
cp.setLayout(null); | |
// Anfang Komponenten | |
jTextArea1ScrollPane.setBounds(32, 24, 200, 100); | |
cp.add(jTextArea1ScrollPane); | |
jButton1.setBounds(200, 168, 75, 25); | |
jButton1.setText("jButton1"); | |
jButton1.setMargin(new Insets(2, 2, 2, 2)); | |
jButton1.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent evt) { | |
jButton1_ActionPerformed(evt); | |
} | |
}); | |
cp.add(jButton1); | |
// Ende Komponenten | |
setVisible(true); | |
} // end of public gui2 | |
// Anfang Methoden | |
public void jButton1_ActionPerformed(ActionEvent evt) { | |
java.util.List<Land> laender = this.myDao.getLaender(); | |
for (Land land: laender) | |
{ | |
jTextArea1.append(land + "\n"); | |
} | |
} // end of jButton1_ActionPerformed | |
// Ende Methoden | |
public static void main(String[] args) { | |
new gui2("gui2"); | |
} // end of main | |
} // end of class gui2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author max | |
*/ | |
import java.util.*; | |
public abstract class Land implements java.lang.Comparable<Land> { | |
private String name; | |
private List<Stadt> staedteListe = new ArrayList<Stadt>(); | |
public Land(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public void setStadt(Stadt pStadt) { | |
staedteListe.add(pStadt); | |
} | |
public Stadt getStadt(int pos) { | |
return staedteListe.get(pos); | |
} | |
public Stadt getHauptstadt() { | |
for (Stadt s : staedteListe) { | |
if (s.isCapital()) { | |
return s; | |
} | |
} | |
return null; | |
} | |
@Override | |
public String toString() { | |
String output = "Name: " + this.getName(); | |
return output; | |
} | |
@Override | |
public int compareTo(Land vergleichsLand) { | |
return this.getName().compareTo(vergleichsLand.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author max | |
*/ | |
import java.util.*; | |
public class Stadt implements Comparable<Stadt> { | |
private String name; | |
private boolean isCapital; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public boolean isCapital() { | |
return isCapital; | |
} | |
public void setCapital(boolean isCapital) { | |
this.isCapital = isCapital; | |
} | |
public Stadt(String name, boolean isCapital) { | |
this.name = name; | |
this.isCapital = isCapital; | |
} | |
public int compareTo(Stadt vergleichsStadt) { | |
return this.getName().compareTo(vergleichsStadt.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
/** | |
* | |
* @author max | |
*/ | |
public class Transfer { | |
private DAO dao = new DAO(); | |
public List<Land> getContries() { | |
return dao.getLaender(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment