projekt  
  einleitung
  applet
  quellcode
über  
  info
  team
quellcode
 
JAVADOC
SOURCECODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;

public class GlobalPanel extends JPanel
{
  private static JLabel xPixelLabel = new JLabel("0");
  private static JLabel yPixelLabel = new JLabel("0");
  //initial x-value
  private static JTextField xMetreText= new JTextField("1500",6);
  private static JTextField yMetreText= new JTextField("1000",6);
  private static JTextField tFText= new JTextField("1",6);
  private static JTextField vFText= new JTextField("25",6);
  private static JCheckBox runSwitch= new JCheckBox("running");
  private static JCheckBox trackSwitch= new JCheckBox("tracking");
  private static JButton clearButton= new JButton("clear");

  static
  {
    //add listeners
    xMetreText.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        double mWidth= Main.str2double(xMetreText.getText());
        xMetreText.setText(Main.double2str(mWidth));
        yMetreText.setText(Main.double2str(mWidth*Screen.height/Screen.width));
        Screen.updateTransform();
      } });
    yMetreText.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        double mHeight= Main.str2double(yMetreText.getText());
        yMetreText.setText(Main.double2str(mHeight));
        double mWidth= mHeight*Screen.width/Screen.height;
        xMetreText.setText(Main.double2str(mWidth));
        Screen.updateTransform();
      } });
    tFText.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        double tFVal= Main.str2double(tFText.getText());
        Physics.setDeltaT((tFVal*Screen.REFRESH_TIME)/1000); //in seconds
        tFText.setText(Main.double2str(tFVal));
      } });
    vFText.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        double vFVal= Main.str2double(vFText.getText());
        vFText.setText(Main.double2str(vFVal));
        Screen.vFactor= vFVal;
        Screen.update();
      } });
    runSwitch.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e)
      {
        if(e.getStateChange()== ItemEvent.SELECTED)
        {
          Screen.DrawLoop.stop= false;
          new Thread(){
            public void run()
            {
              Screen.DrawLoop.loop();
            } }.start();
        }
        if(e.getStateChange()== ItemEvent.DESELECTED)
        {
          Screen.DrawLoop.stop= true;
        }
      } });
    trackSwitch.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e)
      {
        if(e.getStateChange()== ItemEvent.SELECTED)
        {
          //set position of selected mass to screen-center:
          Screen.tracking= true;
        }
        if(e.getStateChange()== ItemEvent.DESELECTED)
        {
          //don't set position of selected mass to screen-center:
          Screen.tracking= false;
        }
      } });
    clearButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e)
      {
        MassPanel.update(-1);
        Physics.masses.clear();
        Screen.update();
      } });
  }

  GlobalPanel()
  {
    //do layout
    this.setBorder(BorderFactory.createTitledBorder("Global"));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
      JPanel numberPanel= new JPanel(new BorderLayout());
        JPanel westPanel= new JPanel(new GridLayout(4,1));
          JPanel xPanel= new JPanel();
          xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
          xPanel.add(new JLabel("X:"));
          xPanel.add(xPixelLabel);
          xPanel.add(new JLabel("p="));
        westPanel.add(xPanel);
          JPanel yPanel= new JPanel();
          yPanel.setLayout(new BoxLayout(yPanel, BoxLayout.X_AXIS));
          yPanel.add(new JLabel("Y:"));
          yPanel.add(yPixelLabel);
          yPanel.add(new JLabel("p="));
        westPanel.add(yPanel);
          JPanel dTPanel= new JPanel();
          dTPanel.setLayout(new BoxLayout(dTPanel, BoxLayout.X_AXIS));
          dTPanel.add(new JLabel("t-Factor="));
        westPanel.add(dTPanel);
          JPanel vPanel= new JPanel();
          vPanel.setLayout(new BoxLayout(vPanel, BoxLayout.X_AXIS));
          vPanel.add(new JLabel("v-Factor="));
        westPanel.add(vPanel);
      numberPanel.add(westPanel, BorderLayout.WEST);
        JPanel centerPanel= new JPanel(new GridLayout(4,1));
        centerPanel.add(xMetreText);
        centerPanel.add(yMetreText);
        centerPanel.add(tFText);
        centerPanel.add(vFText);
      numberPanel.add(centerPanel, BorderLayout.CENTER);
        JPanel eastPanel= new JPanel(new GridLayout(4,1));
        eastPanel.add(new JLabel("m"));
        eastPanel.add(new JLabel("m"));
        eastPanel.add(new JLabel("*"));
        eastPanel.add(new JLabel("*"));
      numberPanel.add(eastPanel, BorderLayout.EAST);
    add(numberPanel);
    JPanel buttonPanel= new JPanel(new BorderLayout());
        trackSwitch.setSelected(false);
        runSwitch.setSelected(false);
      buttonPanel.add(trackSwitch, BorderLayout.NORTH);
      buttonPanel.add(runSwitch, BorderLayout.CENTER);
      buttonPanel.add(clearButton, BorderLayout.EAST);
    add(buttonPanel);
  }

  public static double getXMetres()
  {
    return Main.str2double(xMetreText.getText());
  }

  // initialize if screen is known
  public static void update()
  {
    xMetreText.postActionEvent();
    // initialize time-Factor and v-Factor
    tFText.postActionEvent();
    vFText.postActionEvent();
    xPixelLabel.setText(""+Screen.width);
    yPixelLabel.setText(""+Screen.height);
  }
}