Use Java Timer to move a panel smoothly, need help!
I am using JBuilder to build an Windows Application.
I put everything on the contentPane. There is one Panel I call it "jPanelDemo" and another panel "jPanelText".
Now I want to start a timer, and move jPanelDemo panel from the right side of jPanelText to the same location of jPanelText, when the timer stops, jPanelDemo should place the jPanelText position.
Here is my code:
// declare the timer
Timer timer1 = new Timer(1000,null);
int timerSpeed = 1;
// here is the ActionListener
timer1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
while (jPanelDemo.getLocation().x > jPanelText.getLocation().x)
jPanelDemo.setLocation(jPanelDemo.getLocation().x - timerSpeed, jPanelDemo.getLocation().y);
contentPane.repaint();
jPanelDemo.repaint();
timer1.stop();
// here to ensure jPanelDemo replaced jPanelText
jPanelDemo.setLocation(jPanelText.getLocation().x, jPanelDemo.getLocation().y);
);The timer is triggered by clicking a certain Jbutton.
I did the similar codeing in .NET programming and it worked fine. However, I translate the code to Java. When I run this code, the timer actually works, and jPanelDemo does move and replace the jPanelText.
The problem I am facing now is: when I start the timer, the movement of jPanelDemo cannot be seen, until the timer stopped, the jPanelDemo poped up at the same location of jPanelText.
I tried to use contentPane.repaint(), it doesn't work for me.
Please help me solve this problem.
I do not quite understand what you mean.
I added the ActionListener when I initialize the
controls while the frame is loaded.Yes I missed that but you still have a loop in the event thread which is a NO NO. Maybe this will illustrate AN approach -
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fred702 extends JPanel
public Fred702()
super(null);
setPreferredSize(new Dimension(640, 480));
final JLabel label = new JLabel("Hello");
add(label);
final int deltaT = 50;
new javax.swing.Timer(deltaT, new ActionListener()
double theta = 0.0;
double deltaTheta = 0.2 * Math.PI * deltaT / 1000.0;
int r = 200;
public void actionPerformed(ActionEvent e)
int x = (int)(Math.sin(theta) * r + 0.5 + r);
int y = (int)(Math.cos(theta) * r + 0.5 + r);
label.setBounds(x, y, label.getPreferredSize().width, label.getPreferredSize().height);
theta += deltaTheta;
}).start();
public static void main(String[] args)
JFrame frame = new JFrame("Fred702");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Fred702());
frame.pack();
frame.setVisible(true);
}
Similar Messages
-
My iphone 4S wont allow me to restore a bckup of icloud it has just rebooted the os and for over 24 hours i have been trying to fix it i use this phone for my job so i need help. when i try to restore it says "Your iphone could not be activated becuase the activation server is unavailable, If the problom presests goto apple.com/support" It has done this for 27 hours now PLEASE HELP!!!!!!!!!
- Connect the iPod to the computer and see if iTunes sees it. If it sees it try to get the photos off the iPod.
- Next let the battery fully drain. It will likely take days. After charging for at least an hour try again
- Last, make an appointment at the Genius Bar of an Apple store. -
I am trying to export a video as an flv but the list of possible formats is much shorter than it used to be. I cannot find any way to make an FLV using the newest version of Premiere Pro. Need help fast! I am on a Mac
Support for exporting to FLV and F4V has been removed. To learn more, please consult this blog post: removal of FLV and F4V export features from Adobe Media Encoder, After Effects, and Premiere Pro | After Effects regio…
-
hello, my ipad mini doent work i charged it till the next day and it didn't work i charged it again till the next day and it didn't work what should i do i didn't use my ipad for three days please i need help????
Didn't work in what way. Are you unable to start it up? Does it start but then freezes? Does the screen stay black when you turn it on?
Try this - press the home and power buttons and keep pressing them until the apple logo appears. -
why does creative cloud is still asking serial number after i purchase and it wouldn't let me use it anymore because my trial is over need help NOW PLZ
Hi There,
Kindly try the following steps:
Sign out and sign in to Creative Cloud app: Sign out, Sign in | Creative Cloud Desktop app
Sign in, activation, or connection errors | CS5.5 and later
Thanks.
Atul Saini -
Using java.time.LocalDate class
Hello,
I am using the latest JDK8 build b87 and JDeveloper 11.1.2.1. In the editor, the code insight does not show the java.time.LocalDate class. When I use the LocalDate class, it is highlighted in red. However, I can compile and run the application fine. Other classes in the java.time package, for example, the Clock class is fine. I can use classes from the java.time subpackages fine. How can I fix this issue?
Thanks
KishoriJDeveloper does not support JDK 8 as indicated by the certification matrix.
http://www.oracle.com/technetwork/developer-tools/jdev/index-091111.html
java.time.LocalDate being a new class, code insight does not support the class. -
guys, i need help.... is anyone there have an idea about opengl...? ill attach 4 files that needs to be enhanced or debug for possible errors. to see the canvas... you should have atleast all the needed lib and jar of opengl in your pc.
its urgent, its for our thesis actually....ill be dividing the codes with the use of (" **** ")sign...
* Main.java
* Created on 29 January 2007, 08:12
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package longgong;
* @author welcome
public class Main {
/** Creates a new instance of Main */
public Main() {
* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here
frmMain f = new frmMain();
* frmMain.java
* Created on November 10, 2006, 10:52 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package longgong; // create a floder named longgong and add the class inside
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
* @author all user
public class frmMain extends JFrame implements ActionListener, ChangeListener, ItemListener{
JPanel pnlWest, pnlEast, pnlCenter, pnlSouth, pnlTitle, pnlSlider, pnlPlayers;
JSlider slrSpeed;
JList lstResults;
String varResults [] = new String[31];
JLabel lblPlayers, lblTitle;
JCheckBox lblPlayer1, lblPlayer2, lblPlayer3, lblPlayer4, lblPlayer5, lblPlayer6;
ImageIcon imgDice1;
MyCanvas canvas;
JButton btnStart, btnStop;
JMenuBar menuBar;
JMenu menuFile, menuView, menuHelp;
JMenuItem menuNew, menuExit, menuIn, menuOut, menuHigh, menuPlay, menuAbout;
boolean isNew = false;
/** Creates a new instance of frmMain */
public frmMain() {
setLayout(new BorderLayout());
setTitle("Longgong");
setSize(780,600);
canvas = new MyCanvas(getSize().width, getSize().height);
imgDice1 = new ImageIcon("c:\\java\\images\\one.png");
menuBar = new JMenuBar();
menuFile = new JMenu("File");
menuView = new JMenu("View");
menuHelp = new JMenu("Help");
menuNew = new JMenuItem ("New Game");
menuNew.addActionListener(this);
menuExit = new JMenuItem ("Exit");
menuExit.addActionListener(this);
menuIn = new JMenuItem ("Zoom In");
menuIn.addActionListener(this);
menuOut = new JMenuItem ("Zoom Out");
menuOut.addActionListener(this);
menuHigh = new JMenuItem ("High Score");
menuPlay = new JMenuItem ("How To Play");
menuPlay.addActionListener(this);
menuAbout = new JMenuItem ("About");
menuAbout.addActionListener(this);
menuFile.add(menuNew);
menuFile.add(menuExit);
menuView.add(menuIn);
menuView.add(menuOut);
menuView.add(menuHigh);
menuHelp.add(menuPlay);
menuHelp.add(menuAbout);
menuBar.add(menuFile);
menuBar.add(menuView);
menuBar.add(menuHelp);
setJMenuBar(menuBar);
varResults[0] = "Dice Results";
varResults[1] = "1. 3-4-2";
varResults[2] = "2. 3-1-4";
varResults[3] = "3. 3-6-5";
slrSpeed = new JSlider(0, 100, 0);
slrSpeed.setPaintTicks(true);
slrSpeed.setMinorTickSpacing(1);
slrSpeed.setPaintLabels(true);
slrSpeed.setSnapToTicks(true);
slrSpeed.addChangeListener(this);
slrSpeed.setEnabled(false);
btnStart = new JButton("Start");
btnStart.addActionListener(this);
btnStop = new JButton("Stop");
btnStop.addActionListener(this);
pnlWest = new JPanel();
pnlEast = new JPanel();
pnlCenter = new JPanel();
pnlSouth = new JPanel();
pnlTitle = new JPanel();
pnlSlider = new JPanel();
pnlPlayers = new JPanel();
pnlWest.setLayout(new BorderLayout());
pnlEast.setLayout(new BorderLayout());
pnlEast.setPreferredSize(new Dimension(100,400));
pnlCenter.setLayout(new BorderLayout());
pnlSouth.setLayout(new FlowLayout());
pnlTitle.setLayout(new FlowLayout());
pnlSlider.setLayout(new FlowLayout());
pnlPlayers.setLayout(new BoxLayout(pnlPlayers,BoxLayout.Y_AXIS));
pnlPlayers.setPreferredSize(new Dimension(150,400));
lblPlayers = new JLabel(" Players: Choice (s)");
lblPlayer1 = new JCheckBox("None");
lblPlayer1.addItemListener(this);
lblPlayer2 = new JCheckBox("None");
lblPlayer2.addItemListener(this);
lblPlayer3 = new JCheckBox("None");
lblPlayer3.addItemListener(this);
lblPlayer4 = new JCheckBox("None");
lblPlayer4.addItemListener(this);
lblPlayer5 = new JCheckBox("None");
lblPlayer5.addItemListener(this);
lblPlayer6 = new JCheckBox("None");
lblPlayer6.addItemListener(this);
lstResults = new JList(varResults);
pnlPlayers.add(lblPlayers);
pnlPlayers.add(lblPlayer1);
pnlPlayers.add(lblPlayer2);
pnlPlayers.add(lblPlayer3);
pnlPlayers.add(lblPlayer4);
pnlPlayers.add(lblPlayer5);
pnlPlayers.add(lblPlayer6);
pnlSlider.add(slrSpeed);
pnlSlider.add(btnStart);
pnlSlider.add(btnStop);
pnlEast.add(BorderLayout.CENTER, lstResults);
pnlCenter.add(BorderLayout.SOUTH, pnlSlider);
pnlCenter.add(BorderLayout.CENTER, canvas);
lblTitle = new JLabel("LONGGONG DICE GAME SIMULATION");
pnlTitle.add(lblTitle);
getContentPane().add(BorderLayout.NORTH,pnlTitle);
getContentPane().add(BorderLayout.WEST,pnlPlayers);
getContentPane().add(BorderLayout.EAST,pnlEast);
getContentPane().add(BorderLayout.CENTER, pnlCenter);
getContentPane().add(BorderLayout.SOUTH,pnlSouth);
setResizable(false);
canvas.start();
show();
//name change when player is selected
public void itemStateChanged(ItemEvent e) {
Object source = e.getItemSelectable();
int choice;
if (source == lblPlayer1) {
if (lblPlayer1.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer1);
if (source == lblPlayer2) {
if (lblPlayer2.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer2);
if (source == lblPlayer3) {
if (lblPlayer3.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer3);
if (source == lblPlayer4) {
if (lblPlayer4.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer4);
if (source == lblPlayer5) {
if (lblPlayer5.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer5);
if (source == lblPlayer6) {
if (lblPlayer6.isSelected()) {
frmChoices fchoices = new frmChoices(lblPlayer6);
// if (e.getStateChange() == ItemEvent.DESELECTED)
//...make a note of it...
//slider speed change
public void stateChanged(ChangeEvent e){
canvas.speed(slrSpeed.getValue());
public void actionPerformed (ActionEvent e){
if (e.getActionCommand().equals ("Exit")){
System.exit (0);
//connects to frmNew
if (e.getActionCommand().equals ("New Game")){
frmNew n = new frmNew(this);
lblPlayer1.setText("None");
lblPlayer2.setText("None");
lblPlayer3.setText("None");
lblPlayer4.setText("None");
lblPlayer5.setText("None");
lblPlayer6.setText("None");
isNew = true;
lblPlayer1.setSelected(false);
lblPlayer2.setSelected(false);
lblPlayer3.setSelected(false);
lblPlayer4.setSelected(false);
lblPlayer5.setSelected(false);
lblPlayer6.setSelected(false);
if (e.getActionCommand().equals ("Start")){
slrSpeed.setEnabled(true);
canvas.setRandomDicePosition();
if (e.getActionCommand().equals ("Stop")){
slrSpeed.setValue(0);
slrSpeed.setEnabled(false);
//ADDED
if (e.getActionCommand().equals ("New Game")){
frmNew n = new frmNew(this);
if (e.getActionCommand().equals ("Zoom In")){
canvas.zoomIn();
if (e.getActionCommand().equals ("Zoom Out")){
canvas.zoomOut();
if (e.getActionCommand().equals ("How To Play")){
frmPlay p = new frmPlay();
if (e.getActionCommand().equals ("About")){
frmAbout a = new frmAbout();
package longgong;
// Java classes
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
// GL4Java classes
import gl4java.GLContext;
import gl4java.awt.GLAnimCanvas;
import gl4java.utils.textures.*;
class MyCanvas extends GLAnimCanvas implements KeyListener, MouseListener
// holds information on which keys are held down.
boolean[] keys=new boolean[256];
float xrot; // X Rotation ( NEW )
float yrot; // Y Rotation ( NEW )
float zrot; // Z Rotation ( NEW )
float[] diceRotX = new float[3];
float[] diceRotY = new float[3];
float[] diceRotZ = new float[3];
float[] diceTranX = new float[3];
float[] diceTranY = new float[3];
float[] diceTranZ = new float[3];
float speedValue;
Dice[] D;
float zoom = -15.0f;
public MyCanvas(int w, int h)
super(w, h);
//Registers this canvas to process keyboard events, and Mouse events
addKeyListener(this);
addMouseListener(this);
setAnimateFps(60); // seemed to be essential in getting any performance
speedValue=0.0f;
diceTranX[0] = -2.0f;
diceTranY[0] = 2.0f;
diceTranZ[0] = zoom;
diceTranX[1] = 2.0f;
diceTranY[1] = 1.0f;
diceTranZ[1] = zoom;
diceTranX[2] = 0.0f;
diceTranY[2] = -2.0f;
diceTranZ[2] = zoom;
public void zoomIn(){
zoom=zoom+1.0f;
public void zoomOut(){
zoom=zoom-1.0f;
public void speed(float s){
speedValue=s/100;
/** void reshape(int width, int height) Called after the first paint command. */
public void reshape(int width, int height)
if(height==0)height=1;
gl.glViewport(0, 0, width, height); // Reset The Current Viewport And Perspective Transformation
gl.glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity(); // Reset The Projection Matrix
glu.gluPerspective(45.0f, width / height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
gl.glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
gl.glLoadIdentity(); // Reset The ModalView Matrix
/** void preInit() Called just BEFORE the GL-Context is created. */
public void preInit()
{ doubleBuffer = true; stereoView = false; // buffering but not stereoview
public void setRandomDicePosition(){
for (int i=0; i<3; i++){
D.setCoordinates(diceRotX[i],diceRotY[i],diceRotZ[i],diceTranX[i],diceTranY[i],diceTranZ[i]);
D[i].getRandomDice();
/** void init() Called just AFTER the GL-Context is created. */
public void init()
//float width = (float)getSize().width;
//float height = (float)getSize().height;
D = new Dice[5];
D[0] = new Dice(this);
D[1] = new Dice(this);
D[2] = new Dice(this);
//initialize dice location
for (int i=0; i<3; i++){
D[i].setCoordinates(diceRotX[i],diceRotY[i],diceRotZ[i],diceTranX[i],diceTranY[i],diceTranZ[i]);
D[i].getRandomDice();
gl.glEnable(GL_TEXTURE_2D); //Enable Texture Mapping ( NEW )
gl.glShadeModel(GL_SMOOTH); //Enables Smooth Color Shading
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //This Will Clear The Background Color To Black
gl.glClearDepth(1.0); //Enables Clearing Of The Depth Buffer
gl.glEnable(GL_DEPTH_TEST); //Enables Depth Testing
gl.glDepthFunc(GL_LEQUAL); //The Type Of Depth Test To Do
gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Really Nice Perspective Calculations
public void DrawBoundaries(){
double x,y;
double radius = 5.0f;
gl.glLoadIdentity(); // Reset The View
gl.glTranslatef(0.0f,0.0f,zoom-1.0f);
gl.glRotatef(90.0f,0.0f,0.0f,1.0f);
gl.glColor3f(0.6f,0.3f,0.3f);
gl.glBegin(gl.GL_POLYGON);
// angle is
// x = radius * (cosine of angle)
// y = radius * (sine of angle)
for (double a=0; a<360; a++) {
x = radius * (Math.cos(a));
y = radius * (Math.sin(a));
gl.glVertex3d(x, y, 0.0f);
gl.glEnd();
gl.glColor3f(1.0f,1.0f,1.0f);
public void DrawGLScene()
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
DrawBoundaries();
for (int i=0; i<3; i++){
D[i].startDiceMovement();
D[i].setTz(zoom);
D[i].setSpeed(speedValue);
D[i].drawDice();
for (int i=0; i<3; i++){
//start of loop
if(i!=0){
if (D[0].getMoveLeft()==true){
if ( (D[0].getTx()>=D[i].getTx()-1.0f) && (D[0].getTx()<=D[i].getTx()) ){
if (D[0].getMoveLeft()== true) D[0].setMoveLeft(false);
else D[0].setMoveLeft(true);
}else{
if ( (D[0].getTx()-1<=D[i].getTx()) && (D[0].getTx()-1>=D[i].getTx()-1) ){
if (D[0].getMoveLeft()== true) D[0].setMoveLeft(false);
else D[0].setMoveLeft(true);
if (D[0].getMoveUp()==true){
if ( (D[0].getTy()>=D[i].getTy()-1.0f) && (D[0].getTy()<=D[i].getTy()) ){
if (D[0].getMoveUp()== true) D[0].setMoveUp(false);
else D[0].setMoveUp(true);
}else{
if ( (D[0].getTy()-1<=D[i].getTy()) && (D[0].getTy()-1>=D[i].getTy()-1) ){
if (D[0].getMoveUp()== true) D[0].setMoveUp(false);
else D[0].setMoveUp(true);
}//end of if i!=0
if(i!=1){
if (D[1].getMoveLeft()==true){
if ( (D[1].getTx()>=D[i].getTx()-1.0f) && (D[1].getTx()<=D[i].getTx()) ){
if (D[1].getMoveLeft()== true) D[1].setMoveLeft(false);
else D[1].setMoveLeft(true);
}else{
if ( (D[1].getTx()-1<=D[i].getTx()) && (D[1].getTx()-1>=D[i].getTx()-1) ){
if (D[1].getMoveLeft()== true) D[1].setMoveLeft(false);
else D[1].setMoveLeft(true);
if (D[1].getMoveUp()==true){
if ( (D[1].getTy()>=D[i].getTy()-1.0f) && (D[1].getTy()<=D[i].getTy()) ){
if (D[1].getMoveUp()== true) D[1].setMoveUp(false);
else D[1].setMoveUp(true);
}else{
if ( (D[1].getTy()-1<=D[i].getTy()) && (D[1].getTy()-1>=D[i].getTy()-1) ){
if (D[1].getMoveUp()== true) D[1].setMoveUp(false);
else D[1].setMoveUp(true);
}//end of if i!=1
if(i!=2){
if (D[2].getMoveLeft()==true){
if ( (D[2].getTx()>=D[i].getTx()-1.0f) && (D[2].getTx()<=D[i].getTx()) ){
if (D[2].getMoveLeft()== true) D[2].setMoveLeft(false);
else D[2].setMoveLeft(true);
}else{
if ( (D[2].getTx()-1<=D[i].getTx()) && (D[2].getTx()-1>=D[i].getTx()-1) ){
if (D[2].getMoveLeft()== true) D[2].setMoveLeft(false);
else D[2].setMoveLeft(true);
if (D[2].getMoveUp()==true){
if ( (D[2].getTy()>=D[i].getTy()-1.0f) && (D[2].getTy()<=D[i].getTy()) ){
if (D[2].getMoveUp()== true) D[2].setMoveUp(false);
else D[2].setMoveUp(true);
}else{
if ( (D[2].getTy()-1<=D[i].getTy()) && (D[2].getTy()-1>=D[i].getTy()-1) ){
if (D[2].getMoveUp()== true) D[2].setMoveUp(false);
else D[2].setMoveUp(true);
}//end of if i!=2
//end of loop for i
/** void display() Draw to the canvas. */
// Purely a Java thing. Simple calls DrawGLScene once GL is Initialized
public void display()
for(int i=0;i<3;i++){
glj.gljMakeCurrent(); //Ensure GL is initialised correctly
DrawGLScene();
glj.gljSwap(); //Swap buffers
glj.gljFree(); // release GL
// Key Listener events
public void keyTyped(KeyEvent e){
public void keyPressed(KeyEvent e){
switch(e.getKeyCode())
//Kill app
case KeyEvent.VK_ESCAPE:
System.exit(0);
break;
default :
if(e.getKeyCode()<250) // only interested in first 250 key codes, are there more?
keys[e.getKeyCode()]=true;
break;
public void keyReleased(KeyEvent e){
if(e.getKeyCode()<250) // only interested in first 250 key codes, are there more?
keys[e.getKeyCode()]=false;
// mouse listener events
public void mouseEntered( MouseEvent evt )
Component comp = evt.getComponent();
if( comp.equals(this ) )
//requestFocus();
public void mouseExited( MouseEvent evt ){
public void mousePressed( MouseEvent evt ){
public void mouseReleased( MouseEvent evt ){
public void mouseClicked( MouseEvent evt )
Component comp = evt.getComponent();
if( comp.equals(this ) )
requestFocus();
* Dice.java
* Created on 08 February 2007, 22:26
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package longgong;
import java.net.URL;
import gl4java.GLContext;
import gl4java.awt.GLAnimCanvas;
import gl4java.utils.textures.*;
* @author welcome
public class Dice {
GLAnimCanvas glCanvas ;
URL codeBase;
int[]texture1 = new int[1]; //Storage for one texture ( NEW )
int[]texture2 = new int[1]; //Storage for one texture ( NEW )
int[]texture3 = new int[1]; //Storage for one texture ( NEW )
int[]texture4 = new int[1]; //Storage for one texture ( NEW )
int[]texture5 = new int[1]; //Storage for one texture ( NEW )
int[]texture6 = new int[1]; //Storage for one texture ( NEW )
float rx;
float ry;
float rz;
float tx;
float ty;
float tz;
float speed;
boolean txMoveLeft;
boolean tyMoveUp;
boolean tzMoveFront;
/** Creates a new instance of Dice */
public Dice(GLAnimCanvas g) {
glCanvas = g;
if(!LoadGLTexture("c:\\java\\images\\one.png",texture1)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
if(!LoadGLTexture("c:\\java\\images\\two.png",texture2)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
if(!LoadGLTexture("c:\\java\\images\\three.png",texture3)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
if(!LoadGLTexture("c:\\java\\images\\four.png",texture4)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
if(!LoadGLTexture("c:\\java\\images\\five.png",texture5)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
if(!LoadGLTexture("c:\\java\\images\\six.png",texture6)){
System.out.println("Failed to load Textures,Bailing!");
System.exit(0);
txMoveLeft = true;
tyMoveUp = true;
public boolean inCircleBoundaries(float x, float y, float radius)
float r;
r = (float)Math.sqrt((x*x) + (y*y));
if (r <= radius)
return true;
else
return false;
public void setCoordinates(float corRx,float corRy,float corRz,float corTx,float corTy,float corTz){
rx = corRx;
ry = corRy;
rz = corRz;
tx = corTx;
ty = corTy;
tz = corTz;
public void getRandomDice(){
int num = (int)(Math.random() * 6);
if (num==1){
rx=0.0f;
ry=0.0f;
rz=0.0f;
else if (num==2){
rx=90.0f;
ry=0.0f;
rz=0.0f;
else if (num==3){
rx=0.0f;
ry=-90.0f;
rz=0.0f;
else if (num==4){
rx=0.0f;
ry=90.0f;
rz=0.0f;
else if (num==5){
rx=-90.0f;
ry=0.0f;
rz=0.0f;
else{
rx=180.0f;
ry=0.0f;
rz=0.0f;
public float getTx(){
return tx+0.5f;
public float getTy(){
return ty+0.5f;
public float getTz(){
return tz+0.5f;
public void setTz(float z){
tz=z;
public boolean getMoveLeft(){
return txMoveLeft;
public boolean getMoveUp(){
return tyMoveUp;
public void setMoveLeft(boolean m){
txMoveLeft = m;
public void setMoveUp(boolean m){
tyMoveUp = m;
public void startDiceMovement(){
if (txMoveLeft==true) {
tx+=speed;
else {
tx-=speed;
if (tyMoveUp==true) {
ty+=speed;
else {
ty-=speed;
ry+=(speed*4);
rx+=(speed*4);
//rz+=(speed*2);
//tx+=speed;
//ty+=speed;
//tz+=speed;
if (inCircleBoundaries(tx,ty,3.5f)==false) {
if (tx>=3.0f) txMoveLeft = false;
if (tx<=-3.0f) txMoveLeft = true;
if (ty>=3.0f) tyMoveUp = false;
if (ty<=-3.0f) tyMoveUp = true;
public void setSpeed(float s){
speed = s;
public void drawDice(){
glCanvas.gl.glLoadIdentity(); // Reset The View
glCanvas.gl.glTranslatef(tx,ty,tz);
glCanvas.gl.glRotatef(rx,1.0f,0.0f,0.0f);
glCanvas.gl.glRotatef(ry,0.0f,1.0f,0.0f);
glCanvas.gl.glRotatef(rz,0.0f,0.0f,1.0f);
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture1[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Front Face
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
glCanvas.gl.glEnd();
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture6[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Back Face
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
glCanvas.gl.glEnd();
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture2[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Top Face
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, -1.0f);
glCanvas.gl.glEnd();
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture5[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Bottom Face
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
glCanvas.gl.glEnd();
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture3[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Right face
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, 1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, 1.0f);
glCanvas.gl.glEnd();
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture4[0]);
glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);
// Left Face
glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, 1.0f);
glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, 1.0f, -1.0f);
glCanvas.gl.glEnd();
public boolean LoadGLTexture(String fileName, int textureNumber[])
PngTextureLoader texLoader = new PngTextureLoader(glCanvas.gl, glCanvas.glu);
if(codeBase!=null)
texLoader.readTexture(codeBase, fileName);
else
texLoader.readTexture(fileName);
if(texLoader.isOk())
//Create Texture
glCanvas.gl.glGenTextures(1, textureNumber);
glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, textureNumber[0]);
glCanvas.gl.glTexParameteri(glCanvas.gl.ill attach 4 files that needs to be
enhanced or debug for possible errors. i hate to break it to you, but even if you post this for the seventh time, finding and fixing errors in your code remains your task. -
Ok i currently have Lion on my early 2011 15" MBP. When i try to install Mountain Lion to my mac HD it keeps telling me I cannot because its used for time machine backups. I have done a search and I know I have to delete the backups.backupdb folder but I cannot find it for the life of me. If anyone can help I would really appreciate, thanks!
NikIf you double-click on your hard drive icon the Backups.backupd folder should be on the root level of your drive. Sometimes OS X gets confused and incorrectly puts a Backups.backupd folder on your hard drive. That folder should only appear on a drive used for Time Machine
If you can't find the Backups.backupd folder try using the free EasyFind with both Package Contents and Invisible Files & Folders checked. Search for "Backups.backupd" without the quotes on your hard drive (default selection), not your Time Machine drive. Right-click on the search result and choose to Reveal in Finder. Click on the link that kisuke3 provided and follow those directions
If you can't find a Backups.backupd folder anywhere try booting into Safe Mode by holding down the Shift key right after you hear the startup chime. Keep holding the Shift key down until you see the Apple Logo. The progress bar that appears indicates the progress of the file check that Safe Mode automatically does. Give it time to finish.
Reboot normally and see if the ML installer will work. If it does wait until Spotlight is finishing indexing before turning Time Machine back on. -
Time capsule..new to Mac Need help!!!
I reacently bought a 1T TC. I need to make space in my HD of my Macbook. I connected the TC and has done the backup. My question is, If I erase movies, pictures from my HD on the computer will I be able to get those items back again on my laptop when I want to see them?
Also, can the TC be used as an external drive without being used with time machine? ie: drag my movies, pictures, music to the TC as if it where a pendrive, for example? It seems much more easier for me when I plug a pendrive drag what I want there, eject the pendrive and ewhen I want a file a just plug it in again...Hi,
After your files are backed up using Time Machine, you can delete them from your computer's disk and recover them using Time Machine. However, an Important consideration is that eventually your Time Capsule will fill up and Time Machine will delete your oldest backups to make room for new backups. Since backups are incremental (only new or changed files are saved during subsequent backups), your older files will eventually be deleted from Time Machine. Once they are deleted from your TC, you won't be able to retrieve them. If they have also been deleted from your computer's disk they are gone forever. It is also possible for your Time Capsule disk to crash or the Time Machine files to become corrupted.
You might consider getting another external drive at some point and use it to archive important files. The files on the "archive" disk should never be deleted. Also, the disk in your computer will eventually crash and having important files available (between Time Machine and your archive disks) will make it possible to recover your files. Of course your house could burn down, be hit by tornado, etc.
You can use your TC disk to save files just like any other disk. According to Apple's Time Capsule web page ( http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore.woa/wa/RSLID?nplm=MB 276LL/A );
"Time Capsule also works great as a wireless hard drive whether you have a Mac or PC. It sets up in a snap, giving you a networked hard drive you can use for storing and sharing any kinds of files."
Jay -
Select layer/object will not move in PS, but will move another layer. Need help
I appreciate the help ahead. I cannot figure this out with my Photoshop CC.
Basically when I select a layer on the right, and then go to move the object in that layer, it moves a different layer behind it.
In the screen shot below on the left I am selecting the artwork layer on the right, which is the flip flops on the shirt.
From here I can use the arrows to move the graphic. However, as soon as I use the mouse to select the flip flop graphic and go to move it, the layer selection on the right jumps to the shading and moves a background layer.
What am I doing wrong? Super frustrating!
Running Win 7 x64 8 gig ram, i7, 2 gb Nvidia card.
Thanks!
JasonYou probably have Auto Select Layer on. (Options bar)
-
I haven't used an Apple computer for years. I need help getting started
I just bought a mac mini after 20 years using a PC. I need help getting started. Any beginning manuals out there? Thanks.
New User of Apple wrote:
I just bought a mac mini after 20 years using a PC. I need help getting started. Any beginning manuals out there? Thanks.
Welcome back. Do not overlook the Finder and individual application Help menu support. The links provided above are great starter references. With tongue in cheek, they also may not be as current as the OS X release on your mini, so expect some differences.
Here are a litany of keyboard short-cuts, last updated in June 2012, that may prove selectively beneficial.
For actions like copy(c), paste(v), cut(x), print(p), and select-all(a), substitute the command key instead of control key.
If you right click on a file, this menu will seem familiar. Press the option key and notice the menu changes. If you copy a file(s) from this menu, change to the destination and then press option with the right button menu to see copy file(s) changed to move file(s).
To quickly view a file's contents, left click on the file icon, then press the space bar.
The native file format for OS X is PDF. Thus, when you choose to print, you also have the option to save as PDF with web links preserved.
Enjoy your mini. -
TS2446 i have disable acc all my acc using my laptop. but i cant enable i need help
i need help. i have disable my acc. i need to enable it back. but i cant log in the server with my laptop. keep popping ouit the same ans. no connection or setting problems. kindly solve my situatuion
iTunes: How to move [or copy] your music [library] to a new computer [or another drive] - http://support.apple.com/kb/HT4527 - a somewhat bewildering and not always easily understandable set of options.
Quick answer if you use iTunes' default preferences settings: Copy the entire iTunes folder (and in doing so all its subfolders and files) intact to the other drive. Open iTunes and immediately hold down the Option (alt) key (shift on Windows), then guide it to the iTunes Library.itl file in the moved iTunes folder.
For the record there's this reference for iTunes 11 but it really doesn't strike me as having the specifics you need. iTunes 11 for Mac: Move your library to another computer - http://support.apple.com/kb/PH12168
Windows users see tip at: https://discussions.apple.com/message/18879381
If you put it in the default location of Macintosh HD > Users > *User Name* > Music then you don't even need to start with the option key held down, iTunes will automatically look for it there. (Make sure there isn't anything already in the iTunes folder there that you want to keep since you will be replacing it with the one you are moving.)
Do not confuse (as you did) moving your whole folder and library with moving just media files as in
iTunes for Mac: Moving your iTunes Media folder - http://support.apple.com/kb/HT1449 -
My code is as the following:
String time = "22/May/2008:00:09:44 -0400";
String strDF1 = "dd/MMM/yyyy:HH:mm:ss Z";
SimpleDateFormat sdf1 = new SimpleDateFormat( strDF1 );
Date d1 = ( Date ) sdf1.parse( time );
System.out.println( d1.toString() );
String srtDF2 = "yyyy-mm-dd HH:mm:ss Z";
SimpleDateFormat sdf2 = new SimpleDateFormat( srtDF2 );
String newTime = sdf2.format( d1 );
System.out.println( newTime );
The output is
Thu May 22 00:09:44 EDT 2008
2008-09-22 00:09:44 -0400
So, you see, the format is correctly changed, but the time is wrong.
Please help...
Thanks,
Paul
Edited by: paulur_lee on Aug 8, 2008 10:28 PMyou are right
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html -
Planning to move to Oracle Financials, need help
Hi All,
Currently I am working as a Supply chain management technical consultant. I have good experience in sql, pl/sql, shell and perl scripting. I am planning to move to Oracle financials (I was told that oracle suppy chain market is not that great for a technical guy). I would like to know what all I need to learn to start working as a financials technical guy.
Thanks in advance.I do not quite understand what you mean.
I added the ActionListener when I initialize the
controls while the frame is loaded.Yes I missed that but you still have a loop in the event thread which is a NO NO. Maybe this will illustrate AN approach -
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fred702 extends JPanel
public Fred702()
super(null);
setPreferredSize(new Dimension(640, 480));
final JLabel label = new JLabel("Hello");
add(label);
final int deltaT = 50;
new javax.swing.Timer(deltaT, new ActionListener()
double theta = 0.0;
double deltaTheta = 0.2 * Math.PI * deltaT / 1000.0;
int r = 200;
public void actionPerformed(ActionEvent e)
int x = (int)(Math.sin(theta) * r + 0.5 + r);
int y = (int)(Math.cos(theta) * r + 0.5 + r);
label.setBounds(x, y, label.getPreferredSize().width, label.getPreferredSize().height);
theta += deltaTheta;
}).start();
public static void main(String[] args)
JFrame frame = new JFrame("Fred702");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Fred702());
frame.pack();
frame.setVisible(true);
} -
Please help me I'm lost it says canceling sync after only some songs download I don't know what the problem is I tried to fix it but nothing works I don't know what to do
Hello there, Savagejacob.
The following Knowledge Base article offers up some great steps for unexpected disconnects of your iOS device when syncing:
iOS: Troubleshooting USB-related alerts when syncing
http://support.apple.com/kb/TS5254
Check connections
Try the following steps to check the connection between your device or computer. You might need to do only one of these steps to resolve the issue, so test your connection after each step.
See if the cable connection at the device or computer has come loose or unplugged.
Unplug the cable you're using to connect your iOS device from the USB port on your computer, and then reconnect it. Then unplug it from your iOS device, and reconnect it.
Remove any third-party battery packs or cases from the device and ensure that the USB cable is connected directly to the port on the device.
If your Lightning or 30-pin cable is connected to a keyboard, display or USB hub, try plugging it directly into a USB port on the computer instead.
Close any virtualization apps (such as Parallels or VMWare).
These apps may interfere with your computer's ability to communicate over USB if they aren't properly configured, or up to date. If this resolves the issue, contact the developer of the app to see if an update is available.
Restart your computer.
Restart your iPad, iPhone, or iPod touch.
If you're using an accessory or third-party cable to connect your device, try using an Apple cable with the device instead.
Update to the latest version of iTunes if you have not already.
Disconnect other USB devices from your computer, except for your keyboard and mouse. Then, reconnect your iOS device. If the issue is resolved, reconnect the other USB devices one at a time. Make sure your iOS device is still recognized by the computer after adding back each device.
If one of these steps resolves the issue, but it comes back later, make sure you haven't changed how the device is connected. For example, check to see if you plugged the device into a specific accessory, or used a specific cable that reintroduced the issue.
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro.
Maybe you are looking for
-
Free goods with every line item
Dear All, I have requirement like whenever i create a sale order specific Division ,1% of the order quantity sholud go for free, EX : if Product A order quantity is 10 then system automatically should give Product A quantity 1 for free.
-
I will be on vacation in Canada some questions: if someone in the USA sends me a text while I am in Canada am I paying any extra charges to receive it? If I send a text to someone" in the USA" from my phone while I am in Canada am I paying extra cha
-
Dynamic record group not working when apostrophes are used
Hi Everyone, I have developed a Form for the most part everything is working as expected. However, there is a search functionality that is giving me problems. The issue is that when the user enters search criteria for last_name that has an apostrophe
-
every time I try to call or they call me, my phone beugs I can not immediatly to call, denied access the directory for 2 to 4 minutes after that it works again I tried all but nothing, everything works except the call I have an iPhone 4 Version 6
-
So I was told this by an Apple support member through the online chat, but everything else I've been reading seems contradictory. Every blog post I've read, and even Apple's own website makes it seems like you can screen share on Messages with any co