bibiki 18 Posting Whiz

@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.

bibiki 18 Posting Whiz

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)

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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
        }
    }
bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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?

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

have you tried it to see if it works?

bibiki 18 Posting Whiz

are you sure your code inside your for loop is correct?

ok, I'm sorry. that line is correct but a little redundant...

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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");
bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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...

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

you are in the java forum. my first suggestion, move to c++ forum as you need help writing c++ code.

bibiki 18 Posting Whiz
bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

great. that worked. thank you a lot NormR1.

I swear I did not put that addMouseListener inside paint myself :)

thank you again.

bibiki 18 Posting Whiz

you are very likely right. I call addMouseListener everytime I repaint. I have it called inside my paint method. let me change that.

bibiki 18 Posting Whiz

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

bibiki 18 Posting Whiz

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

bibiki 18 Posting Whiz

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"

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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 …

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

this is a lot shorter. however, it would not work on my mainArray as it is three dimensional. anyways, thanks.

bibiki 18 Posting Whiz

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.

bibiki 18 Posting Whiz

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: …
bibiki 18 Posting Whiz

:)
sounds like that is exactly what I was looking for. thank you Biiim. kind regards.