Sunday, 15 September 2013

Big image on smaller JFrame/Applet

Big image on smaller JFrame/Applet

I have a pretty big image that I want to display on my JFrame and applet,
the JFrame/Applet is 765x503 in size but the image is way larger. I need a
way to display the image in real size. How can I make it so I can move the
screen around to display some of the image and be able to move around the
image?
I want to be able to drag the screen around, not use Scrollbars.

Saturday, 14 September 2013

(Java) Looking for advise on the layout and process I have chosen for this task?

(Java) Looking for advise on the layout and process I have chosen for this
task?

I hope this is in the right place, if not my apologies but could someone
point me in a better direction? I've been working on this problem for 3
days now, Only 6 weeks into my first university class for any programming
at all and the first language we're learning is Java.
The problem is as follows:
Exercise Two (Another algorithm with sub modules)
Design an algorithm which will:
-Input the cost of a product and the amount the customer has tendered for
payment. you may assume that the payment is always > cost. You may also
assume that the cost and the amount paid are always in increments of 5
cents.
The algorithm should:
-Calculate the amount of change required.
-Determine the notes and coins to be given to the customer. -Output both
to the user.
I have made multiple attempts at this and scrapped my code multiple times,
I'm not looking for a solution from anyone, I've put enough into this to
hold out for that, but I am after some commentary on whether or not I am
going in right direction or if not a pointer as to where, also any comment
on the comments I've added to the code would be greatly appreciated.
Thanks for even taking the time to read this and a huge thanks to anyone
that can give me a hand. Cheers everyone
import io.*;
public class CoinChange
{
public static void main (String [] args)
{
double tenderValue;
// How do I make tenderValue and tenderValueInCents equal to multiple
variables and then allow these variables to be added into submodule as I
require?
// Do I need to create a submodule just for this? I attempted to make
multiple lines all equalling the variable name but it didnt seem to like
that either.
tenderValue = int (100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05);
tenderValueInCents = int (10000, 5000, 2000, 1000, 500, 200, 100, 50,
20, 10, 5);
change = calcChange(cashPayed, itemCost);
System.out.println(+change +"total change back");
changeInCents = calcChangeInCents(cashPayed, itemCost);
noteFinder (100, 10000); //Is this enough information required to feed
the variable required into this specific submodule?
noteFinderTemp (50, 5000); //Have a feeling I need to add in all the
variables used in the submodules as well?
noteFinderTemp (20,2000);
noteFinderTemp (10,1000);
noteFinderTemp (5,500);
coinFinder (2,200);
coinFinder (1,100);
coinFinder (0.5,50);
coinFinder (0.2,20);
coinFinder (0.1,10);
coinFinder (0.05,5);
}
private static calcChange(double cashPayed, double itemCost, double
change);
{
// I am not actually required to add in the checking to see if the
values are valid lines I just wanted to see if i could but after two
days at this its starting to drive me up the wall and if theres a
lot more that needs to be done for this bit i can take it out and
come back to trying this after getting the program to compile.
cashPayed=ConsoleInput="Enter cash payed in dollars and cents (xx.xx)";
itemCost=ConsoleInput="Enter cost of item xx.xx)";
if cashPayed>itemCost;
change=cashPayed-itemCost;
return change;
else if cashPayed<itemCost;
requiredMoney=itemCost-cashPayed;
System.out.println("Please provide" +requiredMoney +"to complete
transaction.");
system.exit;
else if cashPayed==itemCost;
System.out.println("Thankyou, payment complete.");
system.exit;
}
private static calcChangeInCents(double cashPayed, cashPayedInCents
double itemCost, itemCostInCents double changeInCents);
{
cashPayedInCents=cashPayed*100;
itemCostInCents=itemCost*100;
changeInCents=cashPayedInCents-itemCostInCents;
return changeInCents;
}
private static noteFinder ( double tenderValue, tenderValueInCents,
changeInCents, tenderValueQuantity, tempChangeInCents);
{
tenderValueQuantity=changeInCents/tenderValueInCents;
tempChangeInCents=changeInCents%tenderValue;
if (tenderValueQuantity=0 && tempChangeInCents=0);
system.exit; //is this an adequete way to say if these values are
zero then end program?
else if tenderValueQuantity=>1;
//DO I NEED TO PUT THIS IN? maths.RoundDown(tenderValueQuantity); OR
ANOTHER WAY? LIKE *1000 AND /1000 OR TAKING THE RESULT OF % FROM ORIGINAL?
System.out.println(+tenderValueQuantity +"x $" +tenderValue
+"Notes Change");
else system.out.println("No $" +tendervalue +"Notes required");
if temptChangeInCents=!0;
return tempChangeInCents;
else system.exit;
}
private static noteFinderTemp ( double tenderValue,
tenderValueInCents, changeInCents, tenderValueQuantity,
tempChangeInCents);
{
tenderValueQuantity=tempChangeInCents/tenderValueInCents;
tempChangeInCents=tempChangeInCents%tenderValue;
// This above line^ is the one I am most concerned about, will the
tempChangeInCents override itself in order or will it cause all sorts of
random problems set out like this? If so I'm guessing that I will not be
able to complete this with general submodules subbing in multiple
variables and will have to create a submodule for every tendervalue? This
was my initial thought but hoped there would be a more elegant way to do
it.
if (tenderValueQuantity=0 && tempChangeInCents=0);
system.exit;
else if tenderValueQuantity=>1
System.out.println(+tenderValueQuantity +"x $" +tenderValue
+"Notes change")
else system.out.println("No $" +tendervalue +"Notes required")
if temptChangeInCents=!0 THEN
return tempChangeInCents
else system.exit;
}
private static coinFinder ( double tenderValue, tenderValueInCents,
changeInCents, tenderValueQuantity, tempChangeInCents);
{
tenderValueQuantity=tempChangeInCents/tenderValueInCents;
tempChangeInCents=tempChangeInCents%tenderValue;
if (tenderValueQuantity=0 && tempChangeInCents=0);
system.exit;
else if tenderValueQuantity=>1
System.out.println(+tenderValueQuantity +"x $" +tenderValue
+"Coins change")
else system.out.println("No" +tendervalue +"c coins required")
if temptChangeInCents=!0 THEN
return tempChangeInCents
else system.exit;
}
}'

Which is more efficient recursion or loops?

Which is more efficient recursion or loops?

I am curious which is more efficient for iteration. I am using one to
break up a parse a string into a List. Is recursion more CPU efficient or
is looping? Is either more memory efficient? By looping, I am referring to
for, for each, do while, while, and any other types. Out of these loops
which are more efficient? Or are they all equally? Just curious.

Why it's the best way to implement the image list, the same image list of the gallery apps

Why it's the best way to implement the image list, the same image list of
the gallery apps

I want to implement a list composed of images with 3 columns and multiple
rows,
according to the number of available images. I'm searching in many places
and not found anything about it yet. What better way to make this?

Using Selenium Webdriver how to connect remote database and run test cases from local machine through eclipse

Using Selenium Webdriver how to connect remote database and run test cases
from local machine through eclipse

I am using selenium web driver java built , editor is eclipse. For testing
one of our website I am using Data driven testing by fetching data from
MySQL database.
I dumped the development server database to my local machine and installed
that dumped data in my machine xampp and able to connect to database and
proceed through the testing process.
To connect to my local machine database i am using this connection string
String url1 ="jdbc:mysql://localhost:3306/databasename";
String dbClass = "com.mysql.jdbc.Driver";
Class.forName(dbClass).newInstance();
Connection con = DriverManager.getConnection(url1, "root", "");
Statement stmt = (Statement) con.createStatement();
Now I need to connect to connect to our original development server
database which is in remote server.
Can any one suggest me how to connect to the remote server database and
what changes are needed to be done in the connection string ? what to put
in the host name ? and how I can run my test cases from my local machine
while connecting to remote server database.
Please provide some suggestion

Bitwise memmove

Bitwise memmove

Is their any implementation available for performing a bitwise memmove?
The method should take an additional destination and source bit-offset and
the count should be in bits too.
I saw that ARM provides a non-standard _membitmove, which does exactly
what I need, but I couldn't find it's or any similar method's source.

heroku restart via new API

heroku restart via new API

I'm a bit confused, as there used to be a method in heroku API to restart
processes of an app. Now this API seems to be deprecated and all links are
leading to https://devcenter.heroku.com/articles/platform-api-reference
where I cannot find any information about restart (even the word restart
itself).
Can someone shed some light on it? This is, I believe, along with showing
logs, one of the most important API commands for a dev, as you can do most
of other tasks via heroku webui.