Simple Routplanner (distance calcutaltor) help needed

Discussion in 'Java' started by jazzy, Jan 4, 2012.

  1. jazzy

    jazzy

    Joined:
    Jan 4, 2012
    Messages:
    1
    Likes Received:
    0
    Hi, I am relativley new to Javascript, and a friend of mine helped me start programming, and I would like to present this to my computers teacher at school, yet I have a bit of a hiccup. For some reason a problem keeps popping up. Here is the code, if anybody could help that would be great! (it is partialy in german, because i am in germany, but i dont think, that that should be a problem )

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    /**
    *
    * Beschreibung
    *
    * @version 1.0 vom 1/3/2012
    * @author
    */
    public class RoutenPlaner extends JFrame {
    // Anfang Attribute
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JRadioButton jRadioButton1 = new JRadioButton();
    private JRadioButton jRadioButton2 = new JRadioButton();
    private JRadioButton jRadioButton3 = new JRadioButton();
    ButtonGroup group1 = new ButtonGroup();{
    group1.add(jRadioButton1);
    group1.add(jRadioButton2);
    group1.add(jRadioButton3);
    }
    private JLabel jLabel3 = new JLabel();
    private JRadioButton jRadioButton4 = new JRadioButton();
    private JRadioButton jRadioButton5 = new JRadioButton();
    private JRadioButton jRadioButton6 = new JRadioButton();
    ButtonGroup group2 = new ButtonGroup();{
    group2.add(jRadioButton4);
    group2.add(jRadioButton5);
    group2.add(jRadioButton6);
    }
    private JLabel jLabel4 = new JLabel();
    private JRadioButton jRadioButton7 = new JRadioButton();
    private JRadioButton jRadioButton8 = new JRadioButton();
    private JRadioButton jRadioButton9 = new JRadioButton();
    ButtonGroup group3 = new ButtonGroup();{
    group3.add(jRadioButton7);
    group3.add(jRadioButton8);
    group3.add(jRadioButton9);
    }
    private JButton jButton1 = new JButton();
    int[][] table={{0,423,235}, {423,0,623},{235,623,0}};
    int x = 0;
    int y = 0;
    int distance = 0;
    private JNumberField jNumberField1 = new JNumberField();
    // Ende Attribute
    public RoutenPlaner(String title) {
    // Frame-Initialisierung
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 917;
    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
    jLabel1.setBounds(16, 16, 110, 20);
    jLabel1.setText("Routenplanner");
    cp.add(jLabel1);
    jLabel2.setBounds(16, 56, 110, 20);
    jLabel2.setText("Startort");
    cp.add(jLabel2);
    jRadioButton1.setBounds(16, 88, 100, 20);
    jRadioButton1.setText("Hamburg");
    cp.add(jRadioButton1);
    jRadioButton2.setBounds(16, 120, 100, 20);
    jRadioButton2.setText("Aachen");
    cp.add(jRadioButton2);
    jRadioButton3.setBounds(16, 152, 100, 20);
    jRadioButton3.setText("Berlin");
    cp.add(jRadioButton3);
    jLabel3.setBounds(168, 56, 110, 20);
    jLabel3.setText("Zwischenziel");
    cp.add(jLabel3);
    jRadioButton4.setBounds(168, 88, 100, 20);
    jRadioButton4.setText("Hamburg");
    cp.add(jRadioButton4);
    jRadioButton5.setBounds(168, 120, 100, 20);
    jRadioButton5.setText("Aachen");
    cp.add(jRadioButton5);
    jRadioButton6.setBounds(168, 152, 100, 20);
    jRadioButton6.setText("Berlin");
    cp.add(jRadioButton6);
    jLabel4.setBounds(320, 56, 110, 20);
    jLabel4.setText("Endziel");
    cp.add(jLabel4);
    jRadioButton7.setBounds(320, 88, 100, 20);
    jRadioButton7.setText("Hamburg");
    cp.add(jRadioButton7);
    jRadioButton8.setBounds(320, 120, 100, 20);
    jRadioButton8.setText("Aachen");
    cp.add(jRadioButton8);
    jRadioButton9.setBounds(320, 152, 100, 20);
    jRadioButton9.setText("Berlin");
    cp.add(jRadioButton9);
    jButton1.setBounds(488, 80, 203, 25);
    jButton1.setText("Distance Berechnen");
    jButton1.setMargin(new Insets(2, 2, 2, 2));
    jButton1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    jButton1_ActionPerformed(evt);
    }
    });
    cp.add(jButton1);
    jNumberField1.setBounds(488, 128, 203, 36);
    jNumberField1.setText("");
    cp.add(jNumberField1);
    // Ende Komponenten
    setVisible(true);
    }

    // Anfang Methoden
    public String getSelectedRadioButton(ButtonGroup bg) {
    for (java.util.Enumeration<AbstractButton> e = bg.getElements(); e.hasMoreElements();) {
    AbstractButton b = e.nextElement();
    if (b.isSelected()) return b.getText();
    }
    return null;
    }

    public void jButton1_ActionPerformed(ActionEvent evt) {
    // TODO hier Quelltext einfügen
    x=0;
    y=0;
    distance=0;
    if(jRadioButton1.isSelected()){
    x=0;
    }else{
    if(jRadioButton2.isSelected()){
    x=1;
    }else{
    if(jRadioButton3.isSelected()){
    x=2;
    }
    }
    }
    if(jRadioButton4.isSelected()){
    y=0;
    }else{
    if(jRadioButton5.isSelected()){
    y=1;
    }else{
    if(jRadioButton6.isSelected()){
    y=2;
    }
    }
    }
    distance += table[x][y];

    if(jRadioButton4.isSelected()){
    x=0;
    }else{
    if(jRadioButton5.isSelected()){
    x=1;
    }else{
    if(jRadioButton6.isSelected()){
    x=2;
    }
    }
    }
    if(jRadioButton7.isSelected()){
    y=0;
    }else{
    if(jRadioButton8.isSelected()){
    y=1;
    }else{
    if(jRadioButton9.isSelected()){
    y=2;
    }
    }
    }
    }
    distance+=table[x][y];
    jNumberField1.setInt(distance);
    }
    // Ende Methoden
    public static void main(String[] args) {
    new RoutenPlaner("RoutenPlaner");
    }
    }
     
    jazzy, Jan 4, 2012
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.