|
hi
my problem is that im trying to build a one armed bandit using Java but i carnt figure out the If statement that lets you get:-
3 shapes of the same type win £1
2 shapes of the same type win 50p
one particular shape, say a apple win 20p
my coding that i have already should be below
any help with this problem would be great
thanks
Adam
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.Timer;
public class ConcentricCirclesWithTimer extends JFrame implements ActionListener
{
private JPanel panelDraw;
private JButton btnDraw, btnBye;
private Random random;
private Timer timer;
int width = 10;
int height = 10;
int x= 100;
int y = 100;
int timerCounter = 0;
public static void main(String[] args)
{
ConcentricCirclesWithTimer drawConcentCirc = new
ConcentricCirclesWithTimer();
}
public ConcentricCirclesWithTimer()
{
setLayout(new FlowLayout());
random = new Random();
panelDraw = new JPanel();
panelDraw.setPreferredSize(new Dimension(200, 200));
panelDraw.setBackground(Color.GRAY);
btnBye = new JButton("Bye!!");
btnDraw = new JButton("Draw.. .");
add(panelDraw); add(btnDraw); add(btnBye);
btnDraw.addActionListener(this);
btnBye.addActionListener(this);
setTitle("Using Pannel to Draw . . . .");
setSize(300, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent event){
if (event.getSource()== btnDraw) {
timer = new Timer(400, this);
timer.start();
}// end of if
if (event.getSource() == timer ){
drawConcentricCircles() ;
}
if (event.getSource()== btnBye) {
System.exit(0);
}
}// end of actionPerformed
private void drawConcentricCircles(){
// x, y, height and width need to be declared globally?? Why??
// declare them here and run program!!
timerCounter = timerCounter + 1;
Graphics drawOnPanel = panelDraw.getGraphics();
drawOnPanel.setColor(new Color(random.nextInt(255),
random.nextInt(255), random.nextInt(255)));
drawOnPanel.drawOval(x, y, width, height);
width = width+20;
height = height+20;
x = x - 10;
y = y-10;
if (timerCounter>11){
timer.stop();
JOptionPane.showMessageDialog(null,"Timer stopped!!");
}
}
}
|
|
|
|
|
I assume this is a standard 3-wheel slot machine?
You should have a "slot" object defined somewhere, or at least some member variables to hold the "shape" and "color" values of each slot wheel.
The "if" statements aren't writable until we know what to compare them with.
For example, would it be "if (slot1Color == 0)" or "if (slot1.color == Color.RED)" or something else?
All you have written is a skeleton application. None of that concerns the question you wanted help with.
Don't let my name fool you. That's my job.
|
|
|
|
|
hi,
I had developed a chat application it is running well on a single system.I want this chat appl. to be communicated with other system like normal chatting. Plz help me out vth this issue.
thank u.
|
|
|
|
|
How You developed the Code?Is it developed by JAVA Threading?
Please let me know the code so that i can give you the exact way to do it.
thanks
Apurba
|
|
|
|
|
hi apurba,
s i had developed using threading concept.my chatserver is working on a default ip-address .0.0.0.what i want is my chatserver must start by picking up my systems Ip-address.here is the code m using.
protected void start_iChatServer(){
try{
iPortNo=Integer.parseInt(iAcquirePortNo.getText());
System.out.println("Port No." + iPortNo +"/n");
}catch(NumberFormatException e){
System.out.println("\n"+e);
System.out.println("Starting at default port : 1664...");
iPortNo=1664;
}
try{
iChatServer=new ServerSocket(iPortNo);
Int=iChatServer.getInetAddress();
i=iChatServer.getLocalPort();
sad=iChatServer.getLocalSocketAddress();
System.out.println("inetaddress=" + Int+ "localport="+i+ "getlocalsocketaddress="+sad);
isServerRunning=true;
System.out.println("\nServer set up and running at port "+iPortNo+"...\nWelcome to iChat Server v1.0...");
System.out.println("ichatserver=" +iChatServer);
iAcquirePortNo.setEnabled(false);
srtServer.setEnabled(false);
stpServer.setEnabled(true);
iClientList=new ArrayList();
iMainThread=new Thread(this,"iChat Server v1.0");
iMainThread.start();
}catch(IOException e){
System.out.println("\n"+e);
System.out.println("Error occured while setting up the server...\nTry another port...");
}
}
public void run(){
while(iMainThread!=null){
try{
Socket iNewClient=iChatServer.accept();
InfiniteChatClientHandler iNewClientHandle=new InfiniteChatClientHandler(this,iNewClient);
Thread.sleep(1000);
}catch(InterruptedException e){
}catch(IOException e){
}
}
}
Thank u
have a nice day.
|
|
|
|
|
I have 5 java classes and I want make them an executable one.
I use Netbeans IDE.
|
|
|
|
|
With Java you create JARs instead. Google that phrase and that should help. I think there are ways to turn Java apps into .exe files, but I have never done it, and that completely destroys most pros of Java.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Pls help me when to use these technologies in any kind of business application.........
|
|
|
|
|
This is more like a general rant, but the problem I'm facing right now is with Java update, so here goes.
I have a Japanese Win XP computer because I work in a Japanese company. I cannot read Japanese. I specifically downloaded the English version of Java and installed it so I would be able to read the messages.
Now that it wants to update, it only does so in Japanese. That means the screens with all the prompting are in Japanese, and the buttons labeled "okay" or "no, this will wipe your hard disk, don't do it!" are also unreadable.
Can someone explain to me why Sun, in their infinite wisdom, decided users shouldn't be able to easily override their default computer settings so that the user can decide what language he wants to read? I already know why Microsoft does it, but "for the money" doesn't seem appropriate for Java.
Also, I realize that sometimes they say "just change your locale settings", but that isn't good enough. In XP, there are about 5 different locale-related items I can change, and at least two of them force me to reboot my computer. I want something to affect the Java update, and only the Java update (and possibly other Java settings). I don't want to reboot my computer just for one program, then reboot again when it's finished. That is a BAD SOLUTION.
*breathes*
Okay, I'm just going to go wipe my hard disk now. Thanks for listening.
|
|
|
|
|
I need an applet where a user enters (or cut-n-pastes) a UTF-8 string into a TextField. Then the user presses a button, and the UTF-8 text is copied into a string.
|
|
|
|
|
Then write one?
What is your specific question/problem?
Don't let my name fool you. That's my job.
|
|
|
|
|
I figured it out shortly after creating this post. I'm using JavaCC to parse my UTF8 inputs, and it's working fine! Thanks for your reply.
|
|
|
|
|
Hello folks,
i'm searching for a class or any sample code to organize a graph (map or network).
I try to explain better, i just want to display a graph in a fine way, clear and well spaced.
Thanks in advance
Program your life ^^
|
|
|
|
|
dear master,,,
I plan to make GPS application in Hand Phone (SE C702) using J2ME,,,
until know, I still confuse about step by step to build this application,,,,
I hope anyone can help to save me from this problem,,,
Cry
thanks,,,,
|
|
|
|
|
Hi guys if any one could help me out with this would be appriciated
I m using servlet as a controller and I have a following html tag and href to pass clicked text to servlet using javascript for further processing. I m not getting it right.
Please look at the code snippet
|
|
|
|
|
can any one help in creating a unstructered p2p n/w.......
|
|
|
|
|
I was wondering if anyone could help me. I have a number of .JAR files which I want to be able to access from VB. I have downloaded a utility which converts the .JAR file into a .DLL which means I can access it using VB code. Unfortunately the software was evaluation only and very expensive. Does anyone know of a free utility that does this or another solution ? The software was from the following site:
http://www.ezjcom.com
Thanks,
Raj
|
|
|
|
|
Thank U Mr.RaJ...........
By Ramesh (GNIIT)
|
|
|
|
|
Dear All,
I've been trying to display the Tif image into the WebBrowser with the help of Applet embedded into a JSP through NetBeans IDE.
To achieve this goal, I've created 2 projects "NewApplet" which contains the Applet class and "WebApplication1" which has "Index.JSP" which embeds the Applet.
If i execute Only the Applet, it displays the TIF. But if i execute the JSP, it fires the following error:
"URL Scheme is not "file" http://localhost:8084/WebApplication1/alpesh.tif""
Following is the code written NewApplet.Java:
package display;
import javax.swing.JApplet;
import java.awt.BorderLayout;
import java.awt.image.RenderedImage;
import java.io.IOException;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import javax.swing.JOptionPane;
public class NewApplet extends JApplet {
@Override
public void init() {
URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource")));
try
{
File f = new File(FileName);
FileInputStream stream = new FileInputStream(f);
// Create a decoder using that stream.
TIFFDecodeParam tiff = new TIFFDecodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, tiff);
// Get the number of pages.
int pages;
pages = dec.getNumPages();
// Set the application title.
setTitle(pages+" pages in "+filename);
// Create a JDesktop to hold the pages in internal frames.
JDesktopPane desktop = new JDesktopPane();
//getContentPane().add(desktop,BorderLayout.CENTER);
desktop.setSize(400,400);
add(desktop,BorderLayout.CENTER);
// Open all images in the TIFF into the desktop pane.
for(int i=0;i<pages;i++)
{
// Get the image.
RenderedImage ri = dec.decodeAsRenderedImage(i);
// Create and set the user interface of an internal frame.
JInternalFrame jif = new JInternalFrame("Page "+i,true,true,true,true);
jif.getContentPane().add(new JScrollPane(new DisplayJAI(ri)));
jif.setSize(400,400);
jif.pack();
jif.setVisible(true);
// Add the internal frame to the JDesktop.
desktop.add(jif);
}
// Set the application closing behaviour, frame size, and show it.
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
}
}
}
Following is the code written Index.JSP:
<APPLET code="display.NewApplet" ARCHIVE="NewApplet.jar" width=350 height=200>
<param name ="imageSource" value="alpesh.tif"/>
</APPLET>
Any Guesses?
I've added the "dist/NewApplet.jar" in WebApplication1 through the option of "Properties->Build->Packaging" in NetBeans.
Please help!
- Alpesh
- Alpesh Khunt
|
|
|
|
|
that doesn't to be reposted
|
|
|
|
|
Dear All,
I've been trying to display the Tif image into the WebBrowser with the help of Applet embedded into a JSP through NetBeans IDE.
To achieve this goal, I've created 2 projects "NewApplet" which contains the Applet class and "WebApplication1" which has "Index.JSP" which embeds the Applet.
If i execute Only the Applet, it displays the TIF. But if i execute the JSP, it fires the following error:
"URL Scheme is not "file" http://localhost:8084/WebApplication1/alpesh.tif""
Following is the code written NewApplet.Java:
package display;
import javax.swing.JApplet;
import java.awt.BorderLayout;
import java.awt.image.RenderedImage;
import java.io.IOException;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import javax.swing.JOptionPane;
public class NewApplet extends JApplet {
@Override
public void init() {
URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource")));
try
{
File f = new File(FileName);
FileInputStream stream = new FileInputStream(f);
// Create a decoder using that stream.
TIFFDecodeParam tiff = new TIFFDecodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, tiff);
// Get the number of pages.
int pages;
pages = dec.getNumPages();
// Set the application title.
setTitle(pages+" pages in "+filename);
// Create a JDesktop to hold the pages in internal frames.
JDesktopPane desktop = new JDesktopPane();
//getContentPane().add(desktop,BorderLayout.CENTER);
desktop.setSize(400,400);
add(desktop,BorderLayout.CENTER);
// Open all images in the TIFF into the desktop pane.
for(int i=0;i<pages;i++)>
{
// Get the image.
RenderedImage ri = dec.decodeAsRenderedImage(i);
// Create and set the user interface of an internal frame.
JInternalFrame jif = new JInternalFrame("Page "+i,true,true,true,true);
jif.getContentPane().add(new JScrollPane(new DisplayJAI(ri)));
jif.setSize(400,400);
jif.pack();
jif.setVisible(true);
// Add the internal frame to the JDesktop.
desktop.add(jif);
}
// Set the application closing behaviour, frame size, and show it.
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
}
}
}
Following is the code written Index.JSP:
<applet code="display.NewApplet" archive="NewApplet.jar" width="350" height="200">
<param name="imageSource" value="alpesh.tif" />
</applet>
Any Guesses?
I've added the "dist/NewApplet.jar" in WebApplication1 through the option of "Properties->Build->Packaging" in NetBeans.
Please help!
Ritesh
|
|
|
|
|
i am using vector data structure in my code
1- i create the following vector of vector:
Vector<vector><integer>> dataVector= new Vector<vector><integer>>();</integer></vector></integer></vector>
and i need to do the following if some condition is true , create new vector and add to the dataVector
maybe somthing like this
if (condition==turu)
then creat new vector
dataVector.add(new vector)
can any one help me
|
|
|
|
|
sudany_zool wrote: Vector> dataVector= new Vector>();
this is badly formatted.
did you mean Vector<Vector<Integer>> ?
anyway, where are you stuck exactly ?
and to understand your problem better, what is your "vector of vector" supposed to represent ?
|
|
|
|
|
creating a cell class.
The first should be called Cell. It represents one cell (square) of the tic-tac-toe board. It should contain at least one property, the character which occupies the cell. You may use either a blank character (‘ ‘) or a null to indicate an empty Cell, but I think you will find that the blank works better. Cell must also contain the following methods:
Constructor - create the cell and initialize the letter in the cell.
void setCell( char letter) - set the value in the cell.
char getCell( ) - return the letter in the cell.
boolean isEmpty( ) - return true if the Cell holds a blank, false otherwise.
|
|
|
|
|
so, what's your question exactly ?
are you totally stuck with it ? or have you already started something ?
as you might know (you are not supposed to ignore the rules out there), we don't do homeworks...
|
|
|
|
|