Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Prozeduren an Canvas class übergeben

Empfohlene Antworten

hi

ich hab nen kleines problem mit meinem applet. ich habe da ne canvas draufgelegt und auch ne canvas class mit ner paint-prozedur dafür geschrieben. nun müsste ich aus dieser paint-prozedur auf eine prozedur einer anderen classe meines applets zugreifen. kann mir jemand sagen, wie ich das machen kann???

thx

Narg

keiner ne idee? :(

Narg

Hallo,

1. Bitte kein Threadpushing :mod: ;)

2. Ohne Code kann man dein Problem anscheinend schlecht nachvollziehen.

3. Schreiben die wenigsten Applets, auch wenn dein Problem anscheinend nicht Applet spezifisch ist.

Original geschrieben von Narg

ich hab nen kleines problem mit meinem applet. ich habe da ne canvas draufgelegt und auch ne canvas class mit ner paint-prozedur dafür geschrieben. nun müsste ich aus dieser paint-prozedur auf eine prozedur einer anderen classe meines applets zugreifen. kann mir jemand sagen, wie ich das machen kann???

4. Allgemein gesprochen: "Indem du ein Objekt der Klasse erzeugst oder übergibst und die Prozedur aufrufst."

Wenn du näheres wissen willst, siehe Punkt 2.

Gruß Jaraz

ok hier mal der code der beiden classen, um die es geht:


class MyCanvas extends Canvas{


	public void paint(Graphics g){

		g.setFont(new Font("Serif", Font.BOLD, 12));

		Daten.anzeigen(g);

	}

}


class Tabelle{

	private final int tabellenLaenge = 7;

	private float data[] = new float[tabellenLaenge];

	private int index;

	private float neuWert;

	private float summe;

	private float groesster;

	private final int linksObenX = 50;

	private final int linksObenY = 100;

	private final int boxBreite = 60;

	private final int boxHoehe = 40;





	public void anzeigen(Graphics g){

		DecimalFormat dezimal = new DecimalFormat("#0.00");

		int y = linksObenY;

		float faktor, hoehe;

		int ywert = 380;

		int xwert = 170;

		for (int i=0;i<data.length;i++){

			g.drawRect(linksObenX,y,boxBreite,boxHoehe);

			String datenwert = dezimal.format(data[i]);

			g.drawString(datenwert,linksObenX + 5, y + boxHoehe * 3/4);

			y = y + boxHoehe;

		}

		werteBerechnen();

		g.drawString("Summe " + summe, 170, 140);

		faktor = (200/groesster);

		for (int i=0;i<data.length;i++){

				hoehe=(ywert-(faktor*data[i]));

				g.fillRect(xwert,(int)hoehe,20,(int)(faktor*data[i]));

				xwert = xwert + 25;

		}

	}


	public void waehleKomponente(float y){

		index = (int)(y - linksObenY)/boxHoehe;

		if (index<0 || index >=data.length)return;

		data[index] = neuWert;

	}


	public void setzeWert(float Wert){

		neuWert = Wert;

	}


	public void werteBerechnen(){

		summe = 0;

		groesster=0;

		float wert = 0;

		for (int i=0;i<data.length;i++){

			summe = summe + data[i];

			wert=data[i];

			for (int j=0;j<data.length;j++){

				if (wert<data[j]){

					wert=data[j];

				}

			}

			if (groesster<wert){

				groesster=wert;

			}

		}


	}

}


so, die classe tabelle hat eine eigene prozedur, um sich selbst zu zeichnen, aber wenn ich die auf einer canvas darstellen will, muss ich die ja irgendwie an die canvas übergeben. die frage ist halt, wie ich das mache.

thx

Narg

ok habs selbst geschafft, danke Jaraz für den tip.

mfg

Narg

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.