Results 1 to 20 of 36
- 04-27-2012, 11:27 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
- 04-27-2012, 01:23 PM #2
Re: how to drage my card images draw on applet.
Try using a mouse listener and a mouse motion listener.
If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 01:51 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
- 04-27-2012, 01:54 PM #4
Re: how to drage my card images draw on applet.
Hard to say what the problem is. I can not see the code and there are so many ways for programs to not work.but not working..If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 02:01 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
what can I do?, please check my code at once.........
- 04-27-2012, 02:29 PM #6
Re: how to drage my card images draw on applet.
What code?
If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 02:35 PM #7
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
My code is given bellow:
package com.progresso;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JApplet;
public class ShowCard extends JApplet implements MouseListener,Runnable,
MouseMotionListener {
private static final long serialVersionUID = 1L;
Image image,image1,img,img1,Casino_table_img;
MediaTracker tr;
int x=105;
int y=210;
private int _initX = 105;
private int _initY = 210;
private ShowCard _currentCard = null;
private int _dragFromX;
private int _dragFromY;
private static final int IMAGE_WIDTH = 73;
private static final int IMAGE_HEIGHT = 97;
static ShowCard[] _deck = new ShowCard[104];
int[] cards = new int[104];
public Boolean[] nums = new Boolean[52];
AudioClip audioClip;
String suits = "shdcshdc";
String faces = "a23456789tjqk";
int cardPosition = 0;
Image card;
int n=104;
private int[] x1 = {200,220,240,260,280,300,320,340,360,380};
private int[] y1 = {320,320,320,320,320,320,320,320,320,320};
private int[] x2 = {200,220,240,260,280,300,320,340,360,380};
private int[] y2 = {110,110,110,110,110,110,110,110,110,110};
private int[] x83= {100,101,102,103,104,105,106,107,108,109,110,111,1 12,113,114,115,116,117,118,119,120,121,122,123,124 ,125,126,127,128,129,130,131,132,133,134,135,136,1 37,138,139,140,141,142,143,144,145,146,147,148,149 ,150,151,152,153,154,155,156,157,158,159,160,161,1 62,163,164,165,166,167,168,169,170,171,172,173,174 ,175,176,177,178,179,180,181,182,183};
private int[] y83= {210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210};
private int[] x3 = {305};
private int[] y3 = {210};
Random rgen = new Random();
List<Integer> intList = new ArrayList<Integer>();
List<Integer> intList_ten = new ArrayList<Integer>();
List<Integer> intList_ten_user = new ArrayList<Integer>();
List<Integer> intList_ten_83 = new ArrayList<Integer>();
List<Integer> intList_ten_one = new ArrayList<Integer>();
int frame = 0;
volatile Thread thread;
public ShowCard()
{
Demo1(image,x83,y83);
}
public ShowCard(Image image, int[] x83, int[] y83) {
this.image = image;
this.x83 = x83;
this.y83 = y83;
//System.out.println("Card is: "+this.image);
}
public void Demo1(Image image, int[] x832, int[] y832) //here x and y is 0-51;
{
this.image = image;
this.x83 = x832;
this.y83 = y832;
//--- Add mouse listeners.
}
public void init()
{
setSize(800, 500);
setPreferredSize(new Dimension(300, 300));
audioClip = getAudioClip(getCodeBase(), "audio/TestSnd.wav");
img1 = getImage(getCodeBase(),"cards/b.gif");
Casino_table_img = getImage(getCodeBase(),"cards/casino_table2.gif");
try {
System.out.println("1");
for (int suit=0; suit<suits.length(); suit++)
{
for (int face=0; face<faces.length(); face++)
{
//img = getImage(getCodeBase(),"cards/"+ faces.charAt(face)
// + suits.charAt(suit) + ".gif");
card=getImage(getCodeBase(),"cards/"+ faces.charAt(face)
+ suits.charAt(suit) + ".gif");
_deck[cardPosition++] = new ShowCard(card, x83,y83);
}
}
}catch (Exception ex)
{
ex.printStackTrace(System.out);
// handle exception...
}
for (int crd=0; crd<_deck.length; crd++)
{
intList.add(crd);
}
try
{
for(int j =0; j <10; j++)
{
//System.out.println(j);
int randomPosition = rgen.nextInt(intList.size());
System.out.println("Random no. is: "+randomPosition);
intList_ten.add(randomPosition);
intList.remove(randomPosition);
}
for(int j =0; j <10; j++)
{
int randomPosition = rgen.nextInt(intList.size());
System.out.println("Random no. is: "+randomPosition);
intList_ten_user.add(randomPosition);
intList.remove(randomPosition);
}
for (int crd=0; crd<1; crd++)
{
int randomPosition = rgen.nextInt(intList.size());
intList_ten_one.add(randomPosition);
intList.remove(randomPosition);
}
for (int crd=0; crd<intList.size(); crd++)
{
int randomPosition = rgen.nextInt(intList.size());
intList_ten_83.add(randomPosition);
}
}
catch (Exception e) {
System.err.println("Caught IOException: " + e.getMessage());
}
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void start()
{
System.out.println("Start");
}
public void stop()
{
}
public void run() {
int delay = 2000; // 2 second
try {
while (thread == Thread.currentThread()) {
frame = (frame+1)%_deck.length;
repaint();
Thread.sleep(delay);
}
} catch (Exception e) {
}
}
public void paint(Graphics g)
{
//System.out.println("paint");
//super.paintComponents(g); // Required
g.drawImage(Casino_table_img, 20, 20, this);
try{
for(int j =0; j <10; j++)//for ten
{
intList_ten.get(j);
ShowCard c = _deck[intList_ten.get(j)];
g.drawImage(c.image, x1[j],y1[j], this );
}
for(int j =0; j <10; j++)
{
ShowCard c = _deck[intList_ten_user.get(j)];
g.drawImage(c.image,x2[j],y2[j], this);
//g.drawImage(img1,x2[j],y2[j], this);
}
for(int j =0; j <1; j++)
{
ShowCard c = _deck[intList_ten_one.get(j)];
g.drawImage(c.image,x3[j],y3[j], this);
}
for (int crd=0; crd<intList_ten_83.size(); crd++)
{
ShowCard c = _deck[intList_ten_83.get(crd)];
//g.drawImage(c.image, c.x,c.y, this);
g.drawImage(c.image,c.x83[crd],c.y83[crd], this);
//g.drawImage(img1, c.x,c.y, this);
//System.out.println("ok"+c.x+"ok"+c.y);
}
}
catch (Exception e) {
System.err.println("Caught IOException: " + e.getMessage());
}
System.out.println("ok");
}//end paintComponent
public void mousePressed(MouseEvent e) {
int x = e.getX(); // Save the x cord of the click
int y = e.getY(); // Save the y cord of the click
System.out.println(e.getX());
_currentCard = null;
for (int crd=intList.size()-1; crd>=0; crd--) {
ShowCard testCard = _deck[crd];
if (x >= testCard.x && x <= (testCard.x + IMAGE_WIDTH)
&& y >= testCard.x && y <= (testCard.x + IMAGE_HEIGHT)) {
_currentCard= null;
_dragFromX = x - testCard.x; // how far from left
_dragFromY = y - testCard.y; // how far from top
_currentCard = testCard; // Remember what we're dragging.
System.out.println(_currentCard);
break; // Stop when we find the first match.
}
}
}//end mousePressed
/** Set x,y to mouse position and repaint. */
public void mouseDragged(MouseEvent e) {
if (_currentCard != null) { // Non-null if pressed inside card image.
_currentCard.x = e.getX() - _dragFromX;
_currentCard.y = e.getY() - _dragFromY;
//--- Don't move the image off the screen sides
_currentCard.x = Math.max(_currentCard.x, 0);
_currentCard.x = Math.min(_currentCard.x, getWidth()-IMAGE_WIDTH);//407
//System.out.println(e.getX() - _dragFromX);
//--- Don't move the image off top or bottom
_currentCard.y = Math.max(_currentCard.y, 0);
_currentCard.y = Math.min(_currentCard.y, getHeight()-IMAGE_HEIGHT);//403
this.repaint();
}
}//end mouseDragged
public void mouseExited(MouseEvent e) {
_currentCard = null;
System.out.println("7");
}//end mouseExited
//=============================================== Ignore other mouse events.
public void mouseMoved (MouseEvent e) { } // ignore these events
public void mouseEntered (MouseEvent e) { } // ignore these events
public void mouseClicked (MouseEvent e) { } // ignore these events
public void mouseReleased(MouseEvent e) {
audioClip.play();
} // ignore these events
}Last edited by ganesh.gothi@gmail.com; 04-27-2012 at 02:40 PM. Reason: code in tage
- 04-27-2012, 02:36 PM #8
Re: how to drage my card images draw on applet.
Please edit your code and add code tags.
CODE tags not QUOTESLast edited by Norm; 04-27-2012 at 02:43 PM.
If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 04:13 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
Java Code:package com.progresso; import java.applet.AudioClip; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import java.awt.MediaTracker; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.List; import java.util.Random; import javax.swing.JApplet; public class ShowCard extends JApplet implements MouseListener,Runnable, MouseMotionListener { private static final long serialVersionUID = 1L; Image image,image1,img,img1,Casino_table_img; MediaTracker tr; int x=105; int y=210; private int _initX = 105; private int _initY = 210; private ShowCard _currentCard = null; private int _dragFromX; private int _dragFromY; private static final int IMAGE_WIDTH = 73; private static final int IMAGE_HEIGHT = 97; static ShowCard[] _deck = new ShowCard[104]; int[] cards = new int[104]; public Boolean[] nums = new Boolean[52]; AudioClip audioClip; String suits = "shdcshdc"; String faces = "a23456789tjqk"; int cardPosition = 0; Image card; int n=104; private int[] x1 = {200,220,240,260,280,300,320,340,360,380}; private int[] y1 = {320,320,320,320,320,320,320,320,320,320}; private int[] x2 = {200,220,240,260,280,300,320,340,360,380}; private int[] y2 = {110,110,110,110,110,110,110,110,110,110}; private int[] x83= {100,101,102,103,104,105,106,107,108,109,110,111,1 12,113,114,115,116,117,118,119,120,121,122,123,124 ,125,126,127,128,129,130,131,132,133,134,135,136,1 37,138,139,140,141,142,143,144,145,146,147,148,149 ,150,151,152,153,154,155,156,157,158,159,160,161,1 62,163,164,165,166,167,168,169,170,171,172,173,174 ,175,176,177,178,179,180,181,182,183}; private int[] y83= {210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210,210,210,210,2 10,210,210,210,210,210,210,210,210,210,210,210,210 ,210,210,210,210,210,210,210,210,210}; private int[] x3 = {305}; private int[] y3 = {210}; Random rgen = new Random(); List<Integer> intList = new ArrayList<Integer>(); List<Integer> intList_ten = new ArrayList<Integer>(); List<Integer> intList_ten_user = new ArrayList<Integer>(); List<Integer> intList_ten_83 = new ArrayList<Integer>(); List<Integer> intList_ten_one = new ArrayList<Integer>(); int frame = 0; volatile Thread thread; public ShowCard() { Demo1(image,x83,y83); } public ShowCard(Image image, int[] x83, int[] y83) { this.image = image; this.x83 = x83; this.y83 = y83; //System.out.println("Card is: "+this.image); } public void Demo1(Image image, int[] x832, int[] y832) //here x and y is 0-51; { this.image = image; this.x83 = x832; this.y83 = y832; //--- Add mouse listeners. } public void init() { setSize(800, 500); setPreferredSize(new Dimension(300, 300)); audioClip = getAudioClip(getCodeBase(), "audio/TestSnd.wav"); img1 = getImage(getCodeBase(),"cards/b.gif"); Casino_table_img = getImage(getCodeBase(),"cards/casino_table2.gif"); try { System.out.println("1"); for (int suit=0; suit<suits.length(); suit++) { for (int face=0; face<faces.length(); face++) { //img = getImage(getCodeBase(),"cards/"+ faces.charAt(face) // + suits.charAt(suit) + ".gif"); card=getImage(getCodeBase(),"cards/"+ faces.charAt(face) + suits.charAt(suit) + ".gif"); _deck[cardPosition++] = new ShowCard(card, x83,y83); } } }catch (Exception ex) { ex.printStackTrace(System.out); // handle exception... } for (int crd=0; crd<_deck.length; crd++) { intList.add(crd); } try { for(int j =0; j <10; j++) { //System.out.println(j); int randomPosition = rgen.nextInt(intList.size()); System.out.println("Random no. is: "+randomPosition); intList_ten.add(randomPosition); intList.remove(randomPosition); } for(int j =0; j <10; j++) { int randomPosition = rgen.nextInt(intList.size()); System.out.println("Random no. is: "+randomPosition); intList_ten_user.add(randomPosition); intList.remove(randomPosition); } for (int crd=0; crd<1; crd++) { int randomPosition = rgen.nextInt(intList.size()); intList_ten_one.add(randomPosition); intList.remove(randomPosition); } for (int crd=0; crd<intList.size(); crd++) { int randomPosition = rgen.nextInt(intList.size()); intList_ten_83.add(randomPosition); } } catch (Exception e) { System.err.println("Caught IOException: " + e.getMessage()); } this.addMouseListener(this); this.addMouseMotionListener(this); } public void start() { System.out.println("Start"); } public void stop() { } public void run() { int delay = 2000; // 2 second try { while (thread == Thread.currentThread()) { frame = (frame+1)%_deck.length; repaint(); Thread.sleep(delay); } } catch (Exception e) { } } public void paint(Graphics g) { //System.out.println("paint"); //super.paintComponents(g); // Required g.drawImage(Casino_table_img, 20, 20, this); try{ for(int j =0; j <10; j++)//for ten { intList_ten.get(j); ShowCard c = _deck[intList_ten.get(j)]; g.drawImage(c.image, x1[j],y1[j], this ); } for(int j =0; j <10; j++) { ShowCard c = _deck[intList_ten_user.get(j)]; g.drawImage(c.image,x2[j],y2[j], this); //g.drawImage(img1,x2[j],y2[j], this); } for(int j =0; j <1; j++) { ShowCard c = _deck[intList_ten_one.get(j)]; g.drawImage(c.image,x3[j],y3[j], this); } for (int crd=0; crd<intList_ten_83.size(); crd++) { ShowCard c = _deck[intList_ten_83.get(crd)]; //g.drawImage(c.image, c.x,c.y, this); g.drawImage(c.image,c.x83[crd],c.y83[crd], this); //g.drawImage(img1, c.x,c.y, this); //System.out.println("ok"+c.x+"ok"+c.y); } } catch (Exception e) { System.err.println("Caught IOException: " + e.getMessage()); } System.out.println("ok"); }//end paintComponent public void mousePressed(MouseEvent e) { int x = e.getX(); // Save the x cord of the click int y = e.getY(); // Save the y cord of the click System.out.println(e.getX()); _currentCard = null; for (int crd=intList.size()-1; crd>=0; crd--) { ShowCard testCard = _deck[crd]; if (x >= testCard.x && x <= (testCard.x + IMAGE_WIDTH) && y >= testCard.x && y <= (testCard.x + IMAGE_HEIGHT)) { _currentCard= null; _dragFromX = x - testCard.x; // how far from left _dragFromY = y - testCard.y; // how far from top _currentCard = testCard; // Remember what we're dragging. System.out.println(_currentCard); break; // Stop when we find the first match. } } }//end mousePressed /** Set x,y to mouse position and repaint. */ public void mouseDragged(MouseEvent e) { if (_currentCard != null) { // Non-null if pressed inside card image. _currentCard.x = e.getX() - _dragFromX; _currentCard.y = e.getY() - _dragFromY; //--- Don't move the image off the screen sides _currentCard.x = Math.max(_currentCard.x, 0); _currentCard.x = Math.min(_currentCard.x, getWidth()-IMAGE_WIDTH);//407 //System.out.println(e.getX() - _dragFromX); //--- Don't move the image off top or bottom _currentCard.y = Math.max(_currentCard.y, 0); _currentCard.y = Math.min(_currentCard.y, getHeight()-IMAGE_HEIGHT);//403 this.repaint(); } }//end mouseDragged public void mouseExited(MouseEvent e) { _currentCard = null; System.out.println("7"); }//end mouseExited //=============================================== Ignore other mouse events. public void mouseMoved (MouseEvent e) { } // ignore these events public void mouseEntered (MouseEvent e) { } // ignore these events public void mouseClicked (MouseEvent e) { } // ignore these events public void mouseReleased(MouseEvent e) { audioClip.play(); } // ignore these events }
- 04-27-2012, 04:22 PM #10
Re: how to drage my card images draw on applet.
Have you tried debugging the code to see what it is doing? Add lots of printlns to show where the code is executing and the values of variables every time theor values are changed. the print outs will help you understand what the code is doing.
I don't have the images an can not test the code.If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 04:27 PM #11
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
Last edited by ganesh.gothi@gmail.com; 04-27-2012 at 04:29 PM. Reason: add more text.
- 04-27-2012, 04:33 PM #12
Re: how to drage my card images draw on applet.
I am trying to help you solve your problem.
Can you post the debug output that shows how the code is executing and the values of the variables as they change.
Please explain what the code does when it executes and describe what is wrong with what it is doing.
Can you attach a zip with the images?Last edited by Norm; 04-27-2012 at 04:36 PM.
If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 05:01 PM #13
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
In the above code I am trying to develop card game for the user to play, In this code I have draw 10 cards up ( g.drawImage(c.image,x2[j],y2[j], this); ) by and 10 cards down by (g.drawImage(c.image, x1[j],y1[j], this );) and 1 cards in the center on the applet, now the remaining 83 cards of 104, will be displayed on the center as I want. now I want to drag this 83 cards one by one as game will be played and also drag 10 cards that is draw bellow side at
(g.drawImage(c.image, x1[j],y1[j], this );) will be dragged.
So now I want to drag 83 cards one by one, please help me...........
- 04-27-2012, 05:10 PM #14
Re: how to drage my card images draw on applet.
Please post the debug output that shows what is happening when you execute the code and try to drag a card.I want to drag this 83 cards one by one
Does the card move any? Explain what happens when you try to drag a card.
I can not test without the images.If you don't understand my response, don't ignore it, ask a question.
- 04-27-2012, 07:23 PM #15
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
I am not attaching zip file, please download from the URL, please download cards20.zip file show in red color, please download this and test it.......
Java: Example - Card Demo
- 04-27-2012, 07:33 PM #16
Re: how to drage my card images draw on applet.
Please attach a zip. I don't go to third party sites.
Please answer my questions:
Please post the debug output that shows what is happening when you execute the code and try to drag a card.
Does the card move any? Explain what happens when you try to drag a card.If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 08:39 AM #17
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
Re: how to drage my card images draw on applet.
I am using applet tag in html for showing applet on browser. when I am run my above code , it shows all 104 cards and its arrange as 10 up, 10 down, 1 center and remaining 83 also in center as required, now i want to drag first card into 83 cards that is show in top position and drop into other location, this is I am trying to do,,,,,,,,,please help me.......
- 04-28-2012, 12:58 PM #18
Re: how to drage my card images draw on applet.
Please post the debug output that shows what is happening when you execute the code and try to drag a card.
Does the card move any? Explain what happens when you try to drag a card.
I need the images to test the code.If you don't understand my response, don't ignore it, ask a question.
- 04-28-2012, 01:30 PM #19
Member
- Join Date
- Apr 2012
- Posts
- 90
- Rep Power
- 0
- 04-28-2012, 01:47 PM #20
Similar Threads
-
how to generate 10 random card Images in applet graphics
By ganesh.gothi@gmail.com in forum Java AppletsReplies: 20Last Post: 04-19-2012, 08:47 PM -
Need help with assigning deck of card images to array.
By Duffed in forum New To JavaReplies: 11Last Post: 11-25-2011, 04:56 AM -
Draw Large Images
By Sreekanth.m in forum Java 2DReplies: 1Last Post: 09-08-2009, 04:53 PM -
How to draw 2 images with quality?
By Panchitopro in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:31 AM -
How to draw images in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:02 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks