Hallo ich habe jetzt den Originalcode kompilierfähig gemacht.
[JAVA=42]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TemperaturmesserApplet;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
* @author Super-Ali
*/
public class MainApplet2 extends JApplet implements ActionListener {
private int StdIntVal;private int height=680;private int width=680;
private double max_In=0, max_Out=0, max_Klim=0;
private int ind_In, ind_Out, ind_Klim;
private String s;
private Container cont = new Container();
private JPanel diagr = new JPanel();
private JPanel boden = new JPanel();
private JComboBox zeitintval = new JComboBox();
private JComboBox sprung = new JComboBox();
private JButton b1 = new JButton ("<--");
private JButton b2 = new JButton ("-->");
public int sizes=30, start;
//Infos für die Zeichnung
private int [] minuten;
private int [] stunden;
private String [] tag;
//Speicher für richtigen Messewerte
private double [] inside;
private double [] outside;
private double [] klima;
//Datenspeicherplätze
private int [] Temp_Inside= new int[90];
private int [] Temp_Outside= new int[90];
private int [] Temp_Klima=new int[90];
private String [] zeit = new String[90];
private String [] datum = new String[90];
//Wichtige Unterklassen
SSHConnection sshcon;
Refresh ref;
@Override
public void init(){
//StdIntVal = Integer.parseInt(getParameter("Stunden") );
//sizes = Integer.parseInt(getParameter("Bereich"));
for (int i=0; i<90; i++){
Temp_Inside=i;
Temp_Outside=i+3;
Temp_Klima=i+5;
zeit=(i+28)+":"+(i+3);
datum=(i+1)+"-"+(i+3)+"-"+(i+2000);
}
start=Temp_Inside.length;
JLabel zeitint = new JLabel("Zeitintervall:");
StdIntVal=1;
//combobox1 füllen
zeitintval.addItem("30 min");
zeitintval.addItem("60 min");
zeitintval.addItem("120 min");
//combobox2 füllen
sprung.addItem("30 min");
sprung.addItem("60 min");
sprung.addItem("120 min");
b1.addActionListener(this);
b2.addActionListener(this);
zeitintval.addActionListener(this);
cont.setBackground(Color.WHITE);
diagr.setBackground(Color.WHITE);
boden.setBackground(Color.WHITE);
//Frame Initialisierung
//this.setTitle("Temperaturmessdaten Serverraum");
cont.setLayout(new BorderLayout());
//Boden panel initialisieren
boden.setLayout(new GridLayout(1,8));
boden.add(zeitint);
boden.add(zeitintval);
boden.add(new JLabel(" Springe:"));
boden.add(this.sprung);
boden.add(new JLabel(""));
boden.add(this.b1);
boden.add(this.b2);
boden.add(new JLabel(""));
boden.add(new JLabel(""));
//Ende Initialisierung des Boden
//Initialisierung des Container
cont.add(boden, BorderLayout.SOUTH);
cont.add(diagr, BorderLayout.CENTER);
/**try {
sshcon = new SSHConnection(StdIntVal);
sshcon.auslesen();
Temp_Inside = sshcon.getList("inside");
Temp_Outside = sshcon.getList("outside");
Temp_Klima = sshcon.getList("klima");
zeit = sshcon.getZeit();
datum = sshcon.getDatum();
start=Temp_Inside.size();
} catch (IOException ex) {
Logger.getLogger(MainApplet.class.getName()).log(Level.SEVERE, null, ex);
}*/
//Füge Container ins Applet
this.add(cont);
}
public void setStart(int size){
this.start=this.start+size;
if (this.start<=0){
this.start=0;
}
}
private void erzeuge(){
this.minuten = new int [this.sizes];
this.stunden = new int [this.sizes];
this.inside = new double [this.sizes];
this.outside = new double [this.sizes];
this.klima = new double [this.sizes];
this.tag = new String [this.sizes];
}
public void leseDat(){
//System.out.println(this.Temp_Inside);
//System.out.println(this.Temp_Outside);
//System.out.println(this.Temp_Klima);
this.max_In=0;this.max_Out=0;this.max_Klim=0;
int j=0;
//start darf nicht größer als die länge des arraylist sein
if (this.start>=Temp_Inside.length){
this.start=Temp_Inside.length;
}
//der fall, dass man zu weit nach links klickt
if (this.start<=0){
for (int i=0; i<this.sizes; i++){
String [] help = zeit.split(":");
//this.nurUhr=help[0];
this.stunden[j]=Integer.parseInt(help[0]);
this.minuten[j]=Integer.parseInt(help[1]);
//für den datum
help = datum.split("-");
this.tag[j]=help[0]+"."+help[1]+"."+help[2].substring(help[2].length()-2, help[2].length());
// ende datum
this.inside[j]=Temp_Inside;
j+=1;
}
j=0;
for (int i=0; i<this.sizes; i++){
this.outside[j]=Temp_Outside;
j+=1;
}
j=0;
for (int i=0; i<this.sizes; i++){
this.klima[j]=Temp_Klima;
j+=1;
}
}
//normalfall
else {
if (this.start<this.sizes){
this.start=this.sizes;
}
for (int i=this.start-this.sizes; i<this.start; i++){
String [] help = zeit.split(":");
//this.nurUhr=help[0];
this.stunden[j]=Integer.parseInt(help[0]);
this.minuten[j]=Integer.parseInt(help[1]);
//für das datum
help = datum.split("-");
this.tag[j]=help[0]+"."+help[1]+"."+help[2].substring(help[2].length()-2, help[2].length());
//ende datum
this.inside[j]=Temp_Inside;
j+=1;
}
j=0;
for (int i=this.start-this.sizes; i<this.start; i++){
this.outside[j]=Temp_Outside;
j+=1;
}
j=0;
for (int i=this.start-this.sizes; i<this.start; i++){
this.klima[j]=Temp_Klima;
j+=1;
}
}
//höchstwerte
for (int i=0;i<this.inside.length;i++){
if (this.inside>this.max_In){
this.max_In=this.inside;
this.ind_In=i;
}
if (this.outside>this.max_Out){
this.max_Out=this.outside;
this.ind_Out=i;
}
if (this.klima>this.max_Klim){
this.max_Klim=this.klima;
this.ind_Klim=i;
}
}
this.destroy();
}
@Override
public void paint(Graphics g){
this.erzeuge();
this.leseDat();
int line1 =30;
int line2 =630;
//spezialfall zeitintervall =120
if (this.sizes==120){
//g.setColor(Color.white); // Zeichenfarbe auf weiß setzen
//y-achse
g.drawLine(line1, line1-20, line1, this.height);
//x-achse
g.drawLine(line1, line2-60, this.width, line2-60);
//uhrzeit
//g.drawString(this.nurUhr+" Uhr", 570, 2*line1);
//x-achsen beschriftung mit anpassung zur fenstergröße
for (int i=0; i<this.sizes/4; i++){
g.drawLine(line1+i*(this.width-line1)/this.sizes*4, line2-60, line1+i*(this.width-line1)/this.sizes*4, line2+10-60);
if (i==0){
}
else {
g.drawString(this.minuten[i*4]+"", line1+i*(this.width-line1)/this.sizes*4-5, line2+22-60);
}
}
//uhrzeit auf die x-achse drauf
for (int i=0; i<this.minuten.length; i++){
if (this.minuten==0){
if (this.stunden==0){
}else {
g.drawString(this.stunden+" Uhr", line1+i*(this.width-line1)/this.sizes+3, line2-63);
}
}
}
//datum auf die x-achse
for (int i=0; i<this.stunden.length; i++){
//prüfe wann der tag zuende ist
if (this.stunden==0 && this.minuten==0){
g.setColor(Color.red);
g.drawString(this.tag, line1+i*(this.width-line1)/this.sizes+3, line2-63);
g.setColor(Color.black);
}
}
//y-achse beschriftung
for (int i=1; i<40; i++){
if (i<20){
g.drawString(i*2-4+"", line1-25, line2-30*i+4);
}
g.drawLine(line1, line2-15*i, line1-8, line2-15*i);
}
//zeichne graphen
for (int i=0; i<this.sizes-1; i++){
g.setColor(Color.green);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.inside*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.inside[i+1]*15)-60);
g.setColor(Color.red);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.outside*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.outside[i+1]*15)-60);
g.setColor(Color.blue);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.klima*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.klima[i+1]*15)-60);
}
g.setColor(Color.green);
g.drawString("Inside", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 20);
g.drawString(this.max_In+"", line1+this.ind_In*(this.width-line1)/this.sizes, (int) (line2-this.max_In*15)-65);
g.setColor(Color.red);
g.drawString("Outside", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 40);
g.drawString(this.max_Out+"", line1+this.ind_Out*(this.width-line1)/this.sizes, (int) (line2-this.max_Out*15)-65);
g.setColor(Color.blue);
g.drawString("Klima", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 60);
g.drawString(this.max_Klim+"", line1+this.ind_Klim*(this.width-line1)/this.sizes, (int) (line2-this.max_Klim*15)-65);
}
else {
//g.setColor(Color.white); // Zeichenfarbe auf weiß setzen
//y-achse
g.drawLine(line1, line1-20, line1, this.height);
//x-achse
g.drawLine(line1, line2-60, this.width, line2-60);
//uhrzeit
//g.drawString(this.nurUhr+" Uhr", 570, 2*line1);
//x-achsen beschriftung
for (int i=0; i<this.sizes/2; i++){
g.drawLine(line1+i*(this.width-line1)/this.sizes*2, line2-60, line1+i*(this.width-line1)/this.sizes*2, line2+10-60);
//anfangsbeschriftung
if (i==0){
}
else {
g.drawString(this.minuten[i*2]+"", line1+i*(this.width-line1)/this.sizes*2-5, line2+22-60);
}
}
//uhrzeit auf die x-achse drauf
for (int i=0; i<this.minuten.length; i++){
if (this.minuten==0){
if (this.stunden==0){
}else {
g.drawString(this.stunden+" Uhr", line1+i*(this.width-line1)/this.sizes+3, line2-63);
}
}
}
//datum auf die x-achse
for (int i=0; i<this.stunden.length; i++){
//prüfe wann der tag zuende ist
if (this.stunden==0 && this.minuten==0){
g.setColor(Color.red);
g.drawString(this.tag, line1+i*(this.width-line1)/this.sizes+3, line2-63);
g.setColor(Color.black);
}
}
//y-achse beschriftung
for (int i=1; i<40; i++){
if (i<20){
//-4 wegen negativer Temperatur
g.drawString(i*2-4+"", line1-25, line2-30*i+4);
}
g.drawLine(line1, line2-15*i, line1-8, line2-15*i);
}
//zeichne graphen
for (int i=0; i<this.sizes-1; i++){
g.setColor(Color.green);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.inside*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.inside[i+1]*15)-60);
g.setColor(Color.red);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.outside*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.outside[i+1]*15)-60);
g.setColor(Color.blue);
g.drawLine(line1+i*(this.width-line1)/this.sizes, (int) (line2-this.klima*15)-60, line1+(i+1)*(this.width-line1)/this.sizes, (int) (line2-this.klima[i+1]*15)-60);
}
g.setColor(Color.green);
g.drawString("Inside", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 20);
g.drawString(this.max_In+"", line1+this.ind_In*(this.width-line1)/this.sizes, (int) (line2-this.max_In*15)-65);
g.setColor(Color.red);
g.drawString("Outside", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 40);
g.drawString(this.max_Out+"", line1+this.ind_Out*(this.width-line1)/this.sizes, (int) (line2-this.max_Out*15)-65);
g.setColor(Color.blue);
g.drawString("Klima", line1+(this.sizes)*(this.width-line1)/this.sizes-40, 60);
g.drawString(this.max_Klim+"", line1+this.ind_Klim*(this.width-line1)/this.sizes, (int) (line2-this.max_Klim*15)-65);
}
}
/*@Override
public void start(){
}*/
public void actionPerformed(ActionEvent ae) {
String s = (String) this.zeitintval.getSelectedItem();
String [] help = s.split(" ");
sizes=(Integer.parseInt(help[0]));
s=(String) this.sprung.getSelectedItem();
help = s.split(" ");
/**
if (this.zeitintval.getSelectedItem().equals("60 min")){
this.inhalt.setInterval(60);
this.b1.doClick();
this.b2.doClick();
}
else if (this.zeitintval.getSelectedItem().equals("120 min")){
this.inhalt.setInterval(120);
this.b1.doClick();
this.b2.doClick();
}
else if (this.zeitintval.getSelectedItem().equals("30 min")){
this.inhalt.setInterval(30);
this.b1.doClick();
this.b2.doClick();
}*/
if (ae.getActionCommand().equals("<--")){
//die grenzen, negativ darf nicht werden und 0 auch nicht, da sonst doppelt klicken
if (start<=Integer.parseInt(help[0])){
start = start + Integer.parseInt(help[0]);
}
start=start+(-1*Integer.parseInt(help[0]));
if (this.start<=0){
this.start=0;
}
this.repaint();
//System.out.println(this.inhalt.getStart());
}
else if (ae.getActionCommand().equals("-->")){
// auch wieder obere grenze
if (start+Integer.parseInt(help[0])>Temp_Inside.length){
start = Temp_Inside.length-Integer.parseInt(help[0]);
}
start=start+(Integer.parseInt(help[0]));
//System.out.println(this.inhalt.getStart());
this.repaint();
}
}
}
[/code]
Die Messdaten sind nicht echt, doch das Problem ist sichtbar. Erstens muss ich das Applet immer wieder minimieren und neu skalieren um mal ein vernünftiges Bild mit den Buttons unten zu bekommen, zweitens verschwindet die erste Zeichnung nicht, sonder Java überschreibt die Zeichnungen. Ich schätze mal das die update Methode nicht richtig funktioniert, bzw das repaint kein update aufruft....
Ich hoffe ihr könnt mir helfen.
Viele Grüße