Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,450 members, 7,954,766 topics. Date: Saturday, 21 September 2024 at 08:50 AM |
Nairaland Forum / Science/Technology / Programming / Java Cafe (2352 Views)
Wifi Timer Software For Cafe Biz / Please I Need An Original Eassy Browsing Cyber Cafe Timer / Cafe Timer Help (2) (3) (4)
Java Cafe by Dolemite(f): 7:00pm On May 14, 2011 |
I started this topic so people with problems can get help on problems concerning Java. . . I'll begin, I have this code that creates a box, I want to make this box move when buttons are pressed but it doesn't work. . . There are two classes, the main class MovingBox and an inner class move. . . public class MovingBox extends JFrame |
Re: Java Cafe by Fayimora(m): 10:10pm On May 14, 2011 |
Do you want it to move gradually?I mean you see the way it moves or you just want it to disappear and reappear somewhere else, |
Re: Java Cafe by Shimao(m): 11:19pm On May 14, 2011 |
Though there are issues with the structure of your code, there actually isnt any code that moves your box. For you to simulate movement in code, you need to change either the x or y or both coordinate of your target object. Then ofcourse, have the GUI repainted. |
Re: Java Cafe by Dolemite(f): 1:26am On May 15, 2011 |
Shimao:What are these issues? |
Re: Java Cafe by csharpjava(m): 1:27am On May 15, 2011 |
Dolemite The code should look like this:
|
Re: Java Cafe by Shimao(m): 5:42am On May 15, 2011 |
csharpjava has addressed some of it but it could still be better. Declare the initial position of your box and its dimension as variables, so also the distance to move with each key press. Use these as arguments to draw the box. I believe you intend to use a KeyListener, in your event handling code, use a switch to check which key was pressed and increment or decrement the initial x or y position as it would apply, then repaint. Your class need not implement an event handling interface as you may be giving it unintended responsibility. |
Re: Java Cafe by Shimao(m): 6:37am On May 15, 2011 |
Check out this sample implementation code.
|
Re: Java Cafe by Dolemite(f): 3:33pm On May 15, 2011 |
Thanks guys, I knew you geniuses will never let me down. . .at this rate i'll be a genius like you guys in no time, lol. |
Re: Java Cafe by Ajistotle(m): 5:18pm On Jun 10, 2011 |
Evry1 keeps talkin of programming, IDE's and co. After writing a program e.g a java program to add two numbers,how do I turn it into a stand alone application? i.e package it completely and run it on another person's computer |
Re: Java Cafe by Fayimora(m): 5:26pm On Jun 10, 2011 |
Well firstly you have to code it. Secondly you need to implement a user interface and thirdly you deploy. You have to go tru those stages. I dnt think i shud explain more as if you research well on each of these stages you would understand what's up. No offence but it seems to be that you cannot even write d code to do the 1+1. So get to it |
Re: Java Cafe by SayoMarvel(m): 10:10pm On Jun 10, 2011 |
For more info on smooth movement (of your box), study FILTHY RICH CLIENTS; I can't provide lengthy code (working on A̷̷̴ mobile phone) but Swing contains a timing framework that facilitates that. Thumbs up guys. |
Re: Java Cafe by Ajistotle(m): 6:04pm On Jun 13, 2011 |
:d |
Re: Java Cafe by Ajistotle(m): 6:57pm On Jun 13, 2011 |
fayimora, I assure U I can write code to do that. Thanks for the reply |
Re: Java Cafe by Ajistotle(m): 7:02pm On Jun 13, 2011 |
fayimora, I assure U I can write code to do that. Thanks for the reply |
Re: Java Cafe by Fayimora(m): 7:03pm On Jun 13, 2011 |
Aiit cool.lol What language you developing with? |
Re: Java Cafe by Ajistotle(m): 8:04pm On Jun 13, 2011 |
Java. And by d way, I've been stuck on dis 4 a while. Goes lyk dis; write an application that prompts the user to enter the side of a square, then displays a hollow square of dat size made of astericks. Your program should work for squares of all side lengths beteen 1 and 20. I saw it in a java textbook and I cant seem to come up with a working algorithm. Can you help? |
Re: Java Cafe by Fayimora(m): 9:20pm On Jun 13, 2011 |
Sounds interesting, Well you obviously gonna use 2 for loops. One that would print in x number of times on a line and another to print it x number of times vertically. Have you tried it yet? |
Re: Java Cafe by Ajistotle(m): 10:48am On Jun 14, 2011 |
I've tried it using while loops and that's because the question is under the while loop section in the textbook. |
Re: Java Cafe by Fayimora(m): 4:03pm On Jun 14, 2011 |
in this case it rely doesnt matter, Lemme see what you have |
Re: Java Cafe by Danyl(m): 5:00pm On Jun 16, 2011 |
@ajistotle i'll suggest that u package ur code's main class and helper classes(if any) into a .jar file then create an .exe version of ur program by using exe4j software jar-exe executable file converter.u are goin to need a manifest file for that.u can create an installer for it using inno-setup compiler and instal it.by so doing u'll have it as a desktop application. I hope that helps |
Re: Java Cafe by Dolemite(f): 7:45pm On Jun 18, 2011 |
public class UserI am trying to use the 'searchfilesbytype' method to iterate through the hashmap and produce values that are identical to those inputted by the user, but I'm getting an undesirable result. |
Re: Java Cafe by Dolemite(f): 9:04pm On Jun 18, 2011 |
public class UserI am trying to use the 'searchfilesbytype' method to iterate through the hashmap and produce values that are identical to those inputted by the user, but I'm getting an undesirable result. |
Re: Java Cafe by Shimao(m): 7:16am On Jun 19, 2011 |
Your first approach was better. You are using a hashmap to store values so you'll need a keyset to iterate through it. After getting the keyset, use a for, Loop to iterate through the keyset (cos the keyset is a collection of all the keys used to index values in your hashmap) while matching the current key with the supplied key. Once you get a match, break out of the loop. You can handle a no match situation by throwing an exception. Also for your addFile method, you do not need instance variables to hold arguments passed in to your method. You can work directly with the values. |
Re: Java Cafe by Dolemite(f): 5:26pm On Jun 19, 2011 |
public void addFile(String nameIn, String dateIn, String typeIn, int sizeIn){The problem here is I want to check for similarity with the files, where a file with a similar filename would not be added. . .is it possible with an arraylist? |
Re: Java Cafe by wassolldas: 5:50pm On Jun 19, 2011 |
Your code not not compile. A HashMap does not allow duplicate keys. To check if a value exists in a HashMap, use the method - HashMap.containsValue(Object value). Iterating through the set of keys is a performance killer. containsValue public boolean containsValue(Object value) Returns true if this map maps one or more keys to the specified value. Refer to the java API for more information. |
Re: Java Cafe by Dolemite(f): 5:55pm On Jun 19, 2011 |
public void addFile(String nameIn, String dateIn, String typeIn, int sizeIn){I modified it, trying to use a hashmap with an arraylist, it doesn't work. |
Re: Java Cafe by wassolldas: 6:00pm On Jun 19, 2011 |
you should use containsValue, and your check should be on the object not the name of the file |
Re: Java Cafe by Dolemite(f): 6:05pm On Jun 19, 2011 |
File is just a variable name, i'll try that now, |
Re: Java Cafe by Dolemite(f): 6:06pm On Jun 19, 2011 |
Didn't work |
Re: Java Cafe by wassolldas: 6:07pm On Jun 19, 2011 |
post the code |
Re: Java Cafe by Dolemite(f): 6:09pm On Jun 19, 2011 |
private ArrayList<FileSys>file=new ArrayList<FileSys>(); public void addFile(String nameIn, String dateIn, String typeIn, int sizeIn){ |
Re: Java Cafe by wassolldas: 6:15pm On Jun 19, 2011 |
Does FileSys define an equals method? It should override public boolean equals(Object obj) { return (this == obj); } from Object |
Best Of Both Worlds: HTML5 Mobile Web Vs Native Apps / Whats'app Group On Sharepoint / Free Camscan Download
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 40 |