Ich versuche seit Stunden mit verschiedensten Ansätzen ein Bild auf ein JApplet zu zeichnen, mittels Label ist das ja einfach, aber ich hätte es gerne mit der paint oder paintcomponent
[Java]
import java.applet.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Nightbegins extends JPanel {
private static Icon[] Blau = {new ImageIcon("C:/Users/Manfred/Desktop/2.png")};
private static int b = 0;
private static int c = 0;
public static void main(String[] args)
{
run ();
}
public static void run () {
final int d = 0;
final JFrame meinFenster = new JFrame("N");
meinFenster.setTitle("JScrollPane Beispiel");
meinFenster.setSize(500,500);
meinFenster.setLocationRelativeTo(null);
meinFenster.setTitle("ShutTheWar EVOLUTION");
meinFenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel bild = new JLabel(Blau );
bild.setBounds(250,250,10,10);
final Applet BildFenster = new Applet();
BildFenster.setBounds(0, 0, 10000, 10000);
JButton knopf = new JButton ("2");
knopf.setBounds(0, 0, 200, 50);
JButton knopf2 = new JButton ("1");
knopf2.setBounds(200, 0, 200, 50);
knopf.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e) {
int a = (int) (Math.random()*4+1);
if (a==1) {
}
else {
if (a==2){
}
else {
if (a==3){
}
else {
}
}
}
}
});
final JPanel panel = new JPanel();
panel.setBackground(Color.WHITE); panel.setLayout(null);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
panel.setPreferredSize(new Dimension(10000, 10000 ));
JScrollPane scrollPane = new JScrollPane (panel,
v,
h);
knopf2.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e) {
int x = (int) (Math.random()*50+1);
int y = (int) (Math.random()*50+1);
int c = 1 + d;
int d = c;
}
});
BildFenster.add(new Zeichne());
panel.add(bild);
panel.add(knopf);
panel.add(knopf2);
panel.add(BildFenster);
meinFenster.setVisible(true);
meinFenster.getContentPane().add(scrollPane);
}
}
class Zeichne extends JApplet{
ImageIcon Gelb;
Image img1;
Image das;
Dimension Dimension;
MediaTracker TR = new MediaTracker (this);
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
MediaTracker TR = new MediaTracker (this);
TR.addImage(das,0);
das = getImage(getCodeBase(), "f1.jpg");
setBounds(100, 100, 100, 100);
g.drawImage(img1, 200, 200, 200, 200, this);
repaint();
}
}
[/code]
Das ganze soll später einmal mehr werden, deswegen die scrollpane
[Java]
import java.applet.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Nightbegins extends JPanel {
private static Icon[] Blau = {new ImageIcon("C:/Users/Manfred/Desktop/2.png")};
private static int b = 0;
private static int c = 0;
public static void main(String[] args)
{
run ();
}
public static void run () {
final int d = 0;
final JFrame meinFenster = new JFrame("N");
meinFenster.setTitle("JScrollPane Beispiel");
meinFenster.setSize(500,500);
meinFenster.setLocationRelativeTo(null);
meinFenster.setTitle("ShutTheWar EVOLUTION");
meinFenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel bild = new JLabel(Blau );
bild.setBounds(250,250,10,10);
final Applet BildFenster = new Applet();
BildFenster.setBounds(0, 0, 10000, 10000);
JButton knopf = new JButton ("2");
knopf.setBounds(0, 0, 200, 50);
JButton knopf2 = new JButton ("1");
knopf2.setBounds(200, 0, 200, 50);
knopf.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e) {
int a = (int) (Math.random()*4+1);
if (a==1) {
}
else {
if (a==2){
}
else {
if (a==3){
}
else {
}
}
}
}
});
final JPanel panel = new JPanel();
panel.setBackground(Color.WHITE); panel.setLayout(null);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
panel.setPreferredSize(new Dimension(10000, 10000 ));
JScrollPane scrollPane = new JScrollPane (panel,
v,
h);
knopf2.addActionListener(new ActionListener(){
public void actionPerformed(final ActionEvent e) {
int x = (int) (Math.random()*50+1);
int y = (int) (Math.random()*50+1);
int c = 1 + d;
int d = c;
}
});
BildFenster.add(new Zeichne());
panel.add(bild);
panel.add(knopf);
panel.add(knopf2);
panel.add(BildFenster);
meinFenster.setVisible(true);
meinFenster.getContentPane().add(scrollPane);
}
}
class Zeichne extends JApplet{
ImageIcon Gelb;
Image img1;
Image das;
Dimension Dimension;
MediaTracker TR = new MediaTracker (this);
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
MediaTracker TR = new MediaTracker (this);
TR.addImage(das,0);
das = getImage(getCodeBase(), "f1.jpg");
setBounds(100, 100, 100, 100);
g.drawImage(img1, 200, 200, 200, 200, this);
repaint();
}
}
[/code]
Das ganze soll später einmal mehr werden, deswegen die scrollpane