Thank you s.o.s, have a good night.
Thank you s.o.s, have a good night.
Ok, I see. So, once a final variable already hass a value assigned to it, it may not be changed any longer. I think I got it now.
As far as Spring goes, I think one can assign a value to a private variable without either a constructor or a setter method. But I do not know how this is done. Any idea?
s.o.s, thank you for your explanations.
However, this remains unclear:
public class Testing
{
public final String s = null;
public Testing(String s)
{
this.s = s;
}
}
The class won't compile?!
you can use create a web service for that. Build a data access object on your server, make it available via a web service, and access it from anywhere as long as you have internet.
Hey there,
I have the following code:
int[] x = new int[7];
System.out.println(x.lengnth);
x.length = 10;
System.out.println(x.length);
Of course, line three causes a "cannot assign a value to final variable length". However, line one does assign seven to that variable, length.
Now, I have written a Testing class where I have declared a final variable of type String. I tried changing it either via the constructor or via a setter method and they both failed.
Now, my question is: how is length being set when neither a constructor nor a setter method can do this?
Another question would be:
In the Spring framework, when doing dependency injection, even if a variable is private and there is no corresponding setter method, the variable will be changed upon initialization. How is that happening?
Thank you!
I would also like to share this code.
public class SomeClass
{
public int compareNums(int a, int b, int c)
{
return compareNums(compareNums(a, b), c);
}
public int compareNums(int a, int b)
{
if(a < b)return a;
else return b;
}
}
I see people that are usually active and have been active just a few minutes ago, while your post is 4 hours old and they haven't tried to help you. That is because you have provided no code or shown any effort of yours. The guys here don't do other people's homework, I found out.
this what you have here would actually diverge. you need to make some changes to either i, k, or both to make sure that i < m(k - 1) would eventually turn false (if it already is true) so that you get out of your while loop.
anyways, you can define a separate variable somewhere in your code, name it count. insert a System.out.println(count); and a count++; statement at the end of your loop. make sure you initialize your count variable with 1. this would let you see how many times your loop is executing. you can do this many ways, but this is one.
why are you adding l_list to jscrolpane, and then adding l_list to p, and then again adding the jscrollpane to p?
I think you need to set jscrollpane's size first
@taywin, well, the method will be slow. recursion is always slow. But, that is how recursion in this case should be implemented. let us assume the method signature is:
int recursive(int a, int b)
if we implement it recursively, for recursive(5, 6) there should be 6 invocations of the method, and the last to be invoked is the first to be completed... this I believe explains how the method works. the last invocation does not call the method anymore because the 6 must have become 1. I hope this makes any sense now. anyways. kind regards.
let me try:
let as say you want to multiply 5 with 6.
upon first invocation of the method, add 5 to the first input param (that is five), and subtract one from 6. do this as long as the second param is bigger than 1. this, I believe, would be your recursive method. next time I comment, I write code. But writing code is against the rules, so brace yourselves :P
P.S. upon first invocation of the method, add 5 to the first input param (that is five), and subtract one from 6, and add to this the invocation of the method with 5 remaining the same, and pass for the second parameter whatever you get from 6 - 1 (the second parameter subtracted)
Alright, I just solved my problem and this might solve the OP's problem as well.
I had a main method inside my MainFrame class. Instead of instantiating a MainFrame object using the getInstance method, I had new MainFrame inside the main method. Seems like the main method has access to the private constructor that is in the same class, and that is why I was able to start my MainFrame while its instance field was null. Anyways, I hope this is of any help to the OP as well.
I'm having this same issue. I do not want to highjack the thread, but neither am I sure I should start a new thread for the same problem. If a moderator thinks it is better, then I guess they can remove my reply or something.
I have this (a comment where the issue emerges is included):
public class MainFrame extends JFrame
{
private static MainFrame theInstance = null;
private static SuperDAO superDao = null;
private JTabbedPane tabs;
private MainFrame()
{
superDao = SuperDAO.getInstance();
tabs = new JTabbedPane();
//populate tabs
add(tabs);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setSize(500, 500);
pack();
//setResizable(false);
setVisible(true);
}
public static MainFrame getInstance()
{
if(theInstance == null)
theInstance = new MainFrame();
return theInstance;
}
}
//and then I have this other class, that includes this:
public void actionPerformed(ActionEvent e)
{
if(face.equals("refresh"))
{
System.out.println("refreshing");
MainFrame.getInstance();//THIS IS WHERE THINGS GO WRONG
//the first time a press the "refresh button", I get another
//MainFrame, and then the button works fine, that is without producing
//another MainFrame
}
}
I have some ideas, too.
One,
create an app that solves sudoku puzzles. you give it a situation, and then it solves it. You can create a GUI to make challenging your app with a sudoku puzzle easier.
Two,
create an app that seeks, finds, and shows all ways of placing eight chess queens on a chess board with no two of them on the same row, column, or diagonal. Another way to look at the problem is: every row and every column have each exatcly one queen on them.
Three,
create an app that simulates motion of earth around sun, and moon around earth. The challenge here is determining the position of moon as earth moves.
Perhaps a little mathematically challenging, but I did built these when I was more of a beginner, and I believe the experience has helped me.
stultuske, I thought once there is no reference to an object anymore, the object is destroyed... in that case, how would "asd" be referenced again? by recreating it? or am I missing something?
well, go back and use arrays first. that way, you will be able to:
once the button holding the x is clicked, change it's label to "", generate a random number between 0 and the size of your array of buttons, and when you get this number, change the the label of the button that is in that position within the array to "X". you do this algorithm inside your actionPerformed method. I hope this is clear enough.
have you tried it to see if it works?
are you sure your code inside your for loop is correct?
ok, I'm sorry. that line is correct but a little redundant...
you can have conditional sql statements that say something like: CREATE TABLE IF NOT EXISTS... or create database... in that case, you are sure that the database will be created if it does not exist and you won't have to include a .db file, which you can do if you use sqlite.
so, in case you use sqlite, you will have a one-file database that you can place anywhere you want and allow your project to interact with it. however, I am not sure if you can have the .db file inside your jar when using it.
here is how you create jar files via command line. I do not know how to do this using Netbeans as I have never used it.
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
if you've used MySQL with java, using sqlite is just as easy. there are plenty of samples online that you can copy paste into your code or use a guidelines how to use sqlite with java.
I hope this is of any help.
Hey mags11,
your PersonalInformation class looks good to me.
However, your demo is wrong. You still make no use of your PersonalInformation class inside your demo.
Here I will put some comments in your code and let you know what is worng.
Name startName = new Name("Ewan McGregor");//Name is not a class you have built. This is very likely to not compile
startAddress.setAddress();//here, startAddress is the name of the parameter in your PersonalInformation constructor... you can not talk to method parameters. you can only talk to objects. setAddress is a method of a PersonalInformation object. But you have no PersonalInformation object anywhere in your demo, so you cannot invoke setAddress() because you have no object that can set an address. same for below. If you are going to use your setter methods, you will need a constructor of your PersonalInformation objects that takes no parameters. If you pass in parameters, then you need not use setter methods unless you want to change the values in the field variables. This is some hinting. Read this and then read some more of what zeroliken gave you and you should be able to do it.
startAge.setAge("29");
startPhonenumber.setPhoneNumber("2157679834");
well,
this is what I found online. check this link
https://forums.oracle.com/forums/thread.jspa?messageID=9254447
I am confident it will help you.
if your code is c++ you need to put it in a language that MARIE understands. if your code is not in c++, it is in the language MARIE understands, in that case, you'd need to write it in c++. anyways, this "Write the equivalent C++ code in MARIE" tells me that you need to write some code, and the way I understand English, you are asked to write c++ code...
I believe you need to put your jar file in your library folder, I'm sure the place where you got your jar should explain how to install it...
put the errors you get here and we might see what the actual problems are.
include <lou>,
MARIE stands for Machine Architecture that's Real Intuitive and Easy. It is built in Java, but the code you need to write in c++ is not Java code. That is rather a weak imitation of assembly code I think. That code works with the architecture that MARIE represents, that is assembly. And you need to write that in c++. take your question to c++ forum because the language that is used to build a virtual architecture, in this case MARIE, has nothing to do with the code you posted and your assignment.
AND, I really do not care if someone calls me retarded on a forum. But in real life, I'd might mike-tyson one's butt.
you are in the java forum. my first suggestion, move to c++ forum as you need help writing c++ code.
I could be wrong but BranchGroup inside javax sounds doubtful.
javax is a standard java library and it does not contain a media class. if it is to contain it, you should download that. look online for javax.media library.
great. that worked. thank you a lot NormR1.
I swear I did not put that addMouseListener inside paint myself :)
thank you again.
you are very likely right. I call addMouseListener everytime I repaint. I have it called inside my paint method. let me change that.
time indicates the same as what reading points showed.
here is the output. i removed x, y coordinates, and only let time show with the lines "first/second click detected"
first click detected 1331761419281
second click detected 1331761420703
first click detected 1331761425109
second click detected 1331761425109
first click detected 1331761427234
second click detected 1331761427234
first click detected 1331761427234
second click detected 1331761429937
first click detected 1331761429937
second click detected 1331761429937
first click detected 1331761429937
second click detected 1331761436984
first click detected 1331761436984
second click detected 1331761436984
first click detected 1331761436984
second click detected 1331761436984
first click detected 1331761443187
second click detected 1331761443187
first click detected 1331761443187
second click detected 1331761443187
first click detected 1331761443187
second click detected 1331761443187
first click detected 1331761444984
second click detected 1331761444984
first click detected 1331761444984
second click detected 1331761444984
first click detected 1331761445000
second click detected 1331761445000
first click detected 1331761445000
second click detected 1331761450234
first click detected 1331761450234
second click detected 1331761450234
first click detected 1331761450234
second click detected 1331761450234
first click detected 1331761450234
second click detected 1331761450234
first click detected 1331761450234
second click detected 1331761454562
first click detected 1331761454562
second click detected 1331761454562
first click detected 1331761454578
second click detected 1331761454578
first click detected 1331761454578
second click detected 1331761454578
well, if one click prints out both "first click detected" and "second click detected", the point is the same in both instances... what to me is one click seems to be more than one click to my machine.
anyways, I put inside my system outs x and y coordinates and they are the same for all print outs that one click of mine yields.
Here is the output of five clicks on my applet:
----jGRASP exec: appletviewer jgrasphta.htm
first click detected 52 69
second click detected 247 129
first click detected 248 129
second click detected 74 204
first click detected 74 204
second click detected 166 202
first click detected 166 202
second click detected 166 202
first click detected 156 185
second click detected 156 185
first click detected 156 185
second click detected 156 185
first click detected 206 212
second click detected 206 212
first click detected 206 212
second click detected 206 212
first click detected 206 212
----jGRASP: operation complete.
To give you more info on this, see this:
----jGRASP exec: appletviewer jgrasphta.htm
first click detected 52 69 - this is when my first click ends
second click detected 247 129 - this is when my second click ends
first click detected 248 129 - this is when my third click ends
second click detected 74 204
Well, this is my code for mousClicked method:
Point p = ev.getPoint();
if(!firstclick)
{
ls.start_x = (int)p.getX();
ls.start_y = (int)p.getY();
firstclick = true;
System.out.println("first click detected");
}
else
{
ls.end_x = (int)p.getX();
ls.end_y = (int)p.getY();
firstclick = false;
System.out.println("second click detected");
repaint();
}
I expect that this prints either "first click detected" or "second click detected" every time I click on my applet.
One click should not print both, let alone print both more than one time each. However, what I get is:
the first time I click, it prints out "first click detected". the second time I click, I get "second click detected". So far so good. Now on, everything fails. Right now is my third click on the applet, and what I get is:
"first click detected"
"second click detected"
Now on my fourth click on applet I get:
"first click detected"
"second click detected"
"first click detected"
On my fifth click on applet I get:
"first click detected"
"second click detected"
"first click detected"
"second click detected"
On my n-th click, I get (n - 1) lines printed out
.
.
"first click detected"
"second click detected"
.
.
"first click detected"
I put System.outs inside my if-else block...
System.out.println("first click detected");//inside my if, inside mouseClicked
System.out.println("second click detected");//inside my else, inside mouseClicked
Surprisingly, my third click acts as a triple click, my fourth click as a five-tuple (if I said it correctly)... and so on increasing. I do not know what pattern the increase seems to follow.
My third click should be a click alone, not more than one... I can't see what in my code makes it behave as a multiple click.
I put an int i variable, and removed everything else, it behaved as expected.
inside my if, I'd output i and increase it by one.
inside my else, I'd output i and set it to zero.
everything worked fine.
I suspect repaint is somehow messing my code, but I do not know how
UPDATE: Now that I checked, it seems that after the second click, the third counts as two clicks, the fourth as three.. the x-th as x - 1.
Hey there,
I am trying to build an application that listens to my mouse. once I click on my panel, it reads the x, y coordinates of the point I clicked on. Second time I click the panel, it reads the x, y coordinates of this other point and draws a line from the first point to the second.
Here is my code:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class HelloFromVenus extends Applet implements MouseListener
{
LineSegment ls = new LineSegment();
boolean firstclick = false;
int i = 0;
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.fillRect(0, 0, 400, 400);
ls.draw(g);
addMouseListener(this);
}
public void mouseClicked(MouseEvent ev)
{
Point p = ev.getPoint();
if(!firstclick)
{
ls.start_x = (int)p.getX();
ls.start_y = (int)p.getY();
firstclick = true;
System.out.println("first click detected");
}
else
{
ls.end_x = (int)p.getX();
ls.end_y = (int)p.getY();
firstclick = false;
System.out.println("second click detected");
repaint();
}
}
public void mousePressed(MouseEvent ev)
{
}
public void mouseReleased(MouseEvent ev)
{
}
public void mouseEntered(MouseEvent ev)
{
}
public void mouseExited(MouseEvent ev)
{
}
}
//--------------
//LineSegment class is here
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class LineSegment implements Shape
{
int start_x = 0;
int start_y = 0;
int end_x = 0;
int end_y = 0;
public void area()
{
}
public void draw(Graphics g)
{
g.setColor(Color.BLACK);
g.drawLine(start_x, start_y, end_x, end_y);
}
}
//---------------
//shape interface is here
import javax.swing.*;
import java.awt.*;
public interface Shape
{
public void area();
public void draw(Graphics g);
}
Now, the problem …
hey there,
I have some images that I want to use instead of checkboxes in an application I am building.
The images consist of two images. Yes, the two images inside an image are the same except for the background color. One color would indicate when the option the image stands for is selected, and the other for when not selected.
I believe I need to use css to do this. Could someone please tell me how I do this using css?
thank you in advance.
this is a lot shorter. however, it would not work on my mainArray as it is three dimensional. anyways, thanks.
thanks ardav. that is pretty much how I did it. I am using the framework CodeIgniter. I am very interested to utilize MVC as best as possible that sometimes I lose the sense of what is right and what is not right. Somehow I limited myself by assuming that I am supposed to only have one array instead of three passed to my view and so I got stuck. but anyways. thanks for your input.
Hey there,
the following is what I get when I perform a typical query on my database:
+--------+----+---+---+----------+
| length | id | l | p | username |
+--------+----+---+---+----------+
| 50 | 12 | 1 | 1 | bibiki |
| 50 | 12 | 1 | 2 | bibiki |
| 50 | 12 | 2 | 1 | bibiki |
| 50 | 12 | 2 | 2 | bibiki |
| 50 | 12 | 3 | 1 | bibiki |
| 50 | 12 | 3 | 2 | bibiki |
| 40 | 13 | 4 | 5 | bibiki |
| 40 | 13 | 4 | 6 | bibiki |
| 40 | 13 | 5 | 5 | bibiki |
| 40 | 13 | 5 | 6 | bibiki |
+--------+----+---+---+----------+
Note that column id has two different values.
I want my view to look like this:
----------------
id 12
l: 1 2 3
p: 1 2
----------------
id 13
l: 4 5
p: 5 6
----------------
Instead of the above, what I am getting right now is:
------------------
id 12
l: 11 22 33(here I do not want these output twice)
.....and so on
//$mainarray contains the table I put above.
//a print_r on $mainArray looks like this: …
:)
sounds like that is exactly what I was looking for. thank you Biiim. kind regards.
alright, let us say I have this same table as the one you posted:
id, name, orderid, value
1, john, 5, 50.00
1, john, 12, 35.00
1, john, 25, 5.00
1, john, 42, 60.00
Now, assuming that that is on a two-dimensional array, I want to have in my view some thing like this:
User: John
Orders: 5 12 25 42
Values: 50 35 5 60.
Note, John should only display once. Now, one way to do this is for me to put column id on a separate array $ids and then have the loops:
foreach($ids as $i){
echo $i
echo "Orders";
foreach($mainArray as $row){
echo $row['orderid']
}
echo "Values";
foreach($mainArray as $row){
echo $row['value']
}
}
Now, do you know of a better way to do this, or should I just proceed with this idea?
alright Biiim,
now I put the result on an array. Because tablea returns at most 1 result, and let us assume that tableb and tablec return, 2 and 3 results correspondingly, I end up with 6 results in total.
Now, I want to have in my view something like this:
[for the first table]1 result
[for the second table]1 result, 2 result
[for the third table]1 result, 2 result, 3 result
In case of more results from table one, proceed the same as above.
Can you give me some tips on how to do this. Should I split the array of six elements as mentioned above into two arrays... one containing only the results from table1, and then for each element in this new array I'd post the elements from other columns in the initial array as I see fit... or is there perhaps a better way?
What do you think Biiim?
Hey there,
I have these three tables: A, B, and C.
A has a one-to-many relation with both B and C.
Right now, what I am doing is:
I run a select query on A. I put the results on an array, lets say aArray.
For each row in the aArray, I select the corresponding rows from table B and put the results in a two dimensional array bArray.
I do the same for each row in aArray, selecting the corresponding rows from table C.
What I have now is: on array with results from table A, and two two-dimensional arrays with results from B and C.
I do this in my controller. I pass the arrays to my view, and everything is messy. I can make things work this way, but this feels wrong.
Anyone has an idea how I should do this. What I am using is PHP.
thank you in advance.
hey jstfsklh211,
I have it working right now. I do not know what I missed because I forgot what my code looked like when it was not working, but it is working now.
The above is only the general form of what I have now. So the above is correct, but what I had was not exactly what the above generalizes.
thank you though.
you still have your select statement wrong.
put echo $sql in your file and you will see what this statement looks like when you send it to your db. then, ask yourself is that what you want to send to the db. you'll see what the problem is here.
your lines ten and eleven are wrong. you again have typos. you have some single quotes and brackets missing.
In addition, you have nothing happening between these two lines. In that case, line 10 is useless. insert an (echo $sql) statement after these two lines and see what you are asking your database to process. you'll see your mistake.
;) mark your thread solved then. glad I was of help.
hey there,
as part of my application, I build an array of arrays. So, what I have is this:
$mainArray = array();
$mainArray = $somearray;//as built with results from a query
$mainArray = $someOtherArray;//built same as above
//I want to iterate:
foreach($mainArray as $array)
{
foreach($array as $dataArray)
{
echo $dataArray['0'];
}
}
But that seems to not work for me. I tried print_r($dataArray); inside my second foreach loop, but that shows that $dataArray is not read as an array. Rather, print_r prints out ints.
Any idea what's going on?
Thanks in advance.
one of the three constituents of the criteria in the following sql query results to no query (at least one):
$sql = ("SELECT * FROM sc_users WHERE username = '$myusername' and password = '$mypassword' and isadmin = 1 ;");
either you have no user with username gatekeepr (which I believe is the case, it very likely is gatekeeper)... or one of the other two... check for gatekeeper.
P.S. You have gatekeepr spelled wrong.
Hey Marais,
thank you for your idea. However, seems like we both learned something from Chris.
Thank you Chris. That is how I will be creating my database. That suits my needs better.
kind regards.