Guten Morgen zusammen,
ich versuche mittlerweile seit 5std ein Kurfengraph zu schreiben.
Mein Problem an der Sache ist dass das Teil bei mir nicht angezeigt wird.
Mir ist aufegefallen das zwar das repaint() aufgerufen wird aber die paint() nicht.
Das mein Applet
Wäre nett wenn mir da jemand einen Tipp geben könnte.
Danke schon mal im vorraus
ich versuche mittlerweile seit 5std ein Kurfengraph zu schreiben.
Mein Problem an der Sache ist dass das Teil bei mir nicht angezeigt wird.
Mir ist aufegefallen das zwar das repaint() aufgerufen wird aber die paint() nicht.
Code:
package monitor;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Polygon;
public class monitor extends Applet {
int[] data = null;
int[] interval = null;
monitor(int[] data) {
this.data = data;
interval = new int[data.length];
for (int i = 0; i < interval.length; i++) {
interval[i] = i * 10;
}
setBackground(new Color(0));
setSize(new Dimension(super.getWidth(), super.getHeight()));
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawPolygon(getPolygon());
}
void refreshData(int[] data) {
this.data = data;
repaint();
}
private Polygon getPolygon() {
System.out.println(super.getHeight());
Polygon result = new Polygon(interval, data, data.length);
return result;
}
}
Das mein Applet
Code:
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
monitor CPU = new monitor(CPUMonitor);
monitor Mem = new monitor(MemMonitor);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1).addComponent(jLabel2).addComponent(jLabel3).addComponent(jLabel4).addComponent(jLabel5).addComponent(jLabel6).addComponent(jLabel7).addComponent(jLabel8).addComponent(jLabel9).addComponent(jLabel10)).addContainerGap(18, Short.MAX_VALUE)));
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel4).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel5).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel6).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel7).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel8).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel9).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel10).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
jPanel2.setBackground(new java.awt.Color(0, 0, 51));
jPanel2.add(Mem);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 327, Short.MAX_VALUE));
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 83, Short.MAX_VALUE));
jPanel3.setBackground(new java.awt.Color(51, 51, 51));
jPanel3.setPreferredSize(new java.awt.Dimension(320, 80));
jPanel3.add(CPU);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 327, Short.MAX_VALUE));
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 87, Short.MAX_VALUE));
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().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE).addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(jLabel12).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 87, Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel11).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))).addContainerGap()));
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
if ((t = new parser()) != null) {
t.start();
}
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
if (!t.interrupted() && t != null) {
t.interrupt();
t = null;
//Anzeige auf Default stellen
for (int i = 0; i < CPUMonitor.length; i++) {
CPUMonitor[i] = 0;
MemMonitor[i] = 0;
}
}
}
static void refreshCPUMonitor(Integer integer) {
for (int i = 0; i < CPUMonitor.length - 1; i++) {
CPUMonitor[i] = CPUMonitor[i + 1];
}
CPUMonitor[32] = integer;
CPU.refreshData(CPUMonitor);
}
static void refreshMemoryMonitor(Integer integer) {
for (int i = 0; i < MemMonitor.length - 1; i++) {
MemMonitor[i] = MemMonitor[i + 1];
}
MemMonitor[32] = integer;
CPU.refreshData(CPUMonitor);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame myFrame = new view();
myFrame.setVisible(true);
}
});
}
}
Wäre nett wenn mir da jemand einen Tipp geben könnte.
Danke schon mal im vorraus
Zuletzt bearbeitet: