Hei Leute. Ich habe einen RGB Farbwürfel programmiert, der alle 16,7 Milionen Farben anzeigt. nun würde ich gerne einen Slider einbauen, mit dem man diesen Würfel drehen kann. Hier hab ich euch mal den Code:
Gibt es da einen Befehl dafür oder so etwas ? ich möchte ihn um 180° nach links und um 180° nach rechts verschieben können.
Viele Grüße
sweti3
Java:
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import javax.swing.JButton;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import junit.framework.Test;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit [url=http://www.cloudgarden.com]Cloud Garden (Java Resources)[/url] for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewJFrame extends javax.swing.JFrame {
private JButton jBuZeichnen;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public NewJFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jBuZeichnen = new JButton();
getContentPane().add(jBuZeichnen);
jBuZeichnen.setText("Würfel zeichnen");
jBuZeichnen.setBounds(842, 738, 147, 21);
jBuZeichnen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jBuZeichnenActionPerformed(evt);
}
});
}
pack();
this.setSize(1022, 828);
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
private void jBuZeichnenActionPerformed(ActionEvent evt) {
Graphics g = this.getGraphics();
for(int rot=0; rot<=255;rot++){
for (int i=0; i<=255;i++) {
for (int x=0; x<=255;x++) {
g.setColor(new Color(rot,255-i,x));
g.drawLine(+i+rot*1/2,50+x+rot*1/2,+i+1/2*rot,50+x+rot*1/2);
}
}
}
}
}
Gibt es da einen Befehl dafür oder so etwas ? ich möchte ihn um 180° nach links und um 180° nach rechts verschieben können.
Viele Grüße
sweti3