hallo!
habe ein problem mit dem repaint!
ich möchte vom jslider den wert auslesen und dann dementsprechend den text ändern, leider erfolglos....
PHP
import quicktime.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
public class DrawExample extends JPanel implements ActionListener,
WindowListener,
ChangeListener
{
protected JSlider slider = new JSlider(0, 300);
int pxwidth=50;
int pxhight=200;
public void setPxWidth(int width){
pxwidth += width;
}
public void setPxHight(int hight){
pxhight += hight;
}
int getPxWidth(){
return pxwidth;
}
int getPxHight(){
return pxhight;
}
public DrawExample()
{
}
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D)g; //Erzeuge Graphics2D durch casting07. Graphics2D g2d = (Graphics2D)g; //Erzeuge Graphics2D durch casting
g2d.setColor(Color.red); //Farbe setzen
g2d.setFont(new Font("Dialog", Font.BOLD, 30)); //Schriftart defenieren
g2d.drawString("Java 2D rockZ!", pxwidth, pxhight); //Text ausgeben
}
public static void main(String args[])
{
//Frames & Panels
JFrame frame= new JFrame("Java2D Example");
JPanel panel = new JPanel();
panel.setSize(200, 200);
frame.getContentPane().add(new DrawExample());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300); //Groessedes JFrame
frame.setVisible(true); //JFrameanzeigen
frame.getContentPane().add(panel);
//Components
//Slider
JSlider slider = new JSlider(0, 300);
slider.setMinorTickSpacing(1);
slider.setMajorTickSpacing(10);
ChangeListener aChangeListener = new DrawExample();
slider.addChangeListener(aChangeListener);
panel.add(slider);
}
//Slider
public synchronized void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
setPxWidth(source.getValue());
pxwidth = 5;
pxhight = 5;
System.out.println(pxwidth);
repaint();
}
}
Alles anzeigen