Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll need to save the line coordinates if you want to draw more.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your math is basically sound. Keep in mind that the Java sin() & cos() functions use radians instead of degrees and that y increase from 0 to height from top to bottom.

Once you have your starting point, keep an extra pair of variables for previousX and previousY. Each iteration, you are calculating x and y and drawing a line from your previous coord pair to (x,y) and then storing x,y in the previous variables.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, you have come to the wrong site if you want a program given to you.

If you start a new thread, post your code, and ask specific questions, someone may be able to help you with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a very simple line example

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class LinePaintDemo extends JPanel{

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        
        int width = getWidth();
        int height = getHeight();
        int midX = width/2;
        int midY = height/2;
        for (int x=0; x<=midX; x+=3){
            g.drawLine(x, 0, midX, midY);
        }
        for (int x=midX; x<=width; x+=3){
            g.drawLine(x, height, midX, midY);
        }
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new LinePaintDemo());
                frame.setSize(300,300);
                frame.setVisible(true);
            }
        });
    }
}

For your circle, if you vary the angle in a loop, the trig for the line endpoints is trivial.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks Ezzaral! Mistakenly given the suggestion. May I know what it means that is displayed in my header like below:

Infractions: 0/1 (5)

That indicates: [active warnings] / [active infractions] ([points])
You can find more details in your User Control panel under the Infractions heading, including the dates when they will expire. All of that info is visible only to you and moderators. Other users cannot see it, including the header part that you posted above.

I was going to answer this via PM, but since you asked in the thread others may be curious about the answer as well.

If you have other questions, feel free to send a PM so we don't further derail the thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JasonHippy is correct. Advising software piracy is not tolerated here. Any discussion on how to illegally obtain commercial software for free will be removed and the offenders dealt with as per the Keep It Legal rules.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks for all your reply

So, just glancing at your sig, I wonder if you feel this thread is solved?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please do not create multiple threads for a single question. You already have an existing active thread for this question here: http://www.daniweb.com/forums/thread270642.html

Please direct any further discussion to that thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

At line 87, you're setting prev coords equal to the current coords each repaint. You don't want to do that. Leave the prev values where they are at.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps you just need to revalidate() the panel after you've added the new components?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Most of the drawing code itself needs to go into paintComponent(). paintComponent() will be called from the paint() method, so you can still use that with your image.

Update the rendering data in your UI methods and call repaint() to refresh the screen. Let paintComponent() handle the actual drawing of that data onto the graphics reference. You can see an example of that in this post: http://www.daniweb.com/forums/post1146173.html#post1146173 The data is being altered through a Timer, but the concept is still the same when using mouse events.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is most likely your problem then: you should be rendering what the user has drawn by overriding the paintComponent() method on the JPanel.

Your save method is handing a graphics context from the image object you created to the panel to paint on. Unfortunately, that paint operation doesn't include what you've drawn onto the previous (and now invalid) graphics reference that you obtained earlier with getGraphics().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I haven't been able to get it to respond to POST requests. Are you certain that the php page is written to use them? It might only be coded for GET requests like the link you posted.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you tried adding "client.php?" to the string you're sending? I used the following code fragment and pulled back the id just fine

try {
            // Create a URL for the desired page
            URL url = new URL("http://interactivo.mensajito.com/interactivo555/client.php?orden=1&nick=Niche");

            // Read all the text returned by the server
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                // str is one line of text; readLine() strips the newline character(s)
                System.out.println(str);
                Matcher m = Pattern.compile("session=(\\d+)").matcher(str);
                if (m.matches()){
                    System.out.println(">> captured id: "+m.group(1));
                }
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you saying that you don't know how to parse the value you are getting? Or that you aren't able to capture the response at all?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He stated that they are all in the same directory. It's not a classpath issue. His error message is exactly what you get when you try to execute the ".java" file instead of the class. The "." is interpreted as a package separator, hence the "Creature/java" result.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So start working on it and start a new thread when you have an actual question to ask. No one is going to do it for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Also, any suggestions about platform independent solutions?
Java + Open Office

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't try to execute "Creature.java" - execute "Creature" after you have compiled to a class file.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Looks like they pushed 3.6.2 a bit early. I got an update alert today for it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Output:

Enter name: Ferrial P. Esber

A - 1
B - 1
E - 2
F - 1
I - 1
L - 1
P - 1
R - 3
S - 1
Space - 2

Please reply ASAP, thank you very much

I can. It's easy.

One day you will look at it and say the same if you actually spend the time to learn such things. You never will if you ask the internet to do your homework though.

If you post what you have so far and ask some specific questions, perhaps someone here can help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Give it a quick try. It looks like it to me, but I can't test that here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use String.split() with an appropriate expression to turn that into a String[] array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How can I do this?

FILEOUTPUTSTREAM and FILEINPUTSTREAM provide code that will write bytes to file and read them back

With a text editor, of course.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hmm....
nope.

Try again. Show some effort or at least ask a specific question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you bother to read any of the suggestions posted above? Are you completely unable to think for yourself?

Closing this thread. It's long outlived its usefulness.

Salem commented: red red red red red red red red red - Woo Hoo! - green! +19
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you sure that your panel has width and height when you create the BufferedImage? How you are rendering what the user has drawn? What you have there should basically work.

edit: cross-post with BJSJC

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would wear custom t-shirts too, if only I knew where to find some. :(

Salem commented: Y'know that the sig-link spammer OP is cursing you right now ;) +0
Nick Evan commented: Haha :D +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Work for hire topics belong in the Looking To Hire section of the Business Exchange and are not allowed in the technical forums.

If the OP wishes to ask technical questions related to completing his project, he can make a new thread for those.

Closing this thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

But I have been confused for a while. What exactly is this fake signature everyone keeps talking about? I see it referenced all over the place, but I have no idea what it is.

A fake signature is when they put the sig and links directly within the message body, instead of the site-wide user signature.
As in:

Ezzaral
www.example.com

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please be advised that this is not the place to request work for hire or to offer services for such. The proper place for such exchanges is the Business Exchange forums.

If the discussion cannot be kept to a technical discussion nature, I will close the thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yeah, JButton doesn't show a background change too well on several Look And Feels, you could use a JLabel just fine though. Make sure to setOpaque(true) so the background color is shown.

For the timing, you might get by with a simple Swing Timer that sets each color after a tiny delay. Here's a small example of that with a single label. See comments in code

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public class TimerBlink extends javax.swing.JFrame {

    public TimerBlink() {
        initComponents();
        setBounds(100,100,200,150);

        // create a new timer with a delay of 500ms that uses Blinker
        Timer blinkTimer = new Timer(500, new Blinker());
        blinkTimer.start();
    }

    /** this class' actionPerformed() will get called each time the Timer fires */
    class Blinker implements ActionListener{
        boolean on=false;

        public void actionPerformed(ActionEvent e) {
            // blink the label background on and off
            label1.setBackground( on ? Color.BLUE : null);
            on = !on;
        }
    }

    /** everything below here is just inconsequential UI setup */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        label1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        label1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label1.setText("1");
        label1.setOpaque(true);
        getContentPane().add(label1);
        label1.setBounds(20, 20, 90, 40);

        pack();
    }// </editor-fold>

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TimerBlink().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel label1;
    // End of variables declaration

}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If your base class has an executeCode() method, then you should be able to call that just fine in your handler. Your subclasses can override it however they wish. Example:

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class ClickSubclass extends javax.swing.JFrame {

    public ClickSubclass() {
        initComponents();
        add(new LabelA());
        add(new LabelB());
        pack();
    }

    /** base class with mouse handler and a doClickStuff method */
    class LabelA extends JLabel {
        public LabelA(){
            setText("A");
            setPreferredSize(new Dimension(30,30));
            addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    doClickStuff();
                }
            });
        }

        public void doClickStuff(){
            JOptionPane.showMessageDialog(this, "Clicked a LabelA thing");
        }
    }

    /** extends base class and does different "stuff" in doClickStuff method */
    class LabelB extends LabelA{
        public LabelB(){
            super();
            setText("B");
        }

        public void doClickStuff(){
            JOptionPane.showMessageDialog(this, "Clicked a LabelB thing");
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.FlowLayout());

        pack();
    }// </editor-fold>

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClickSubclass().setVisible(true);
            }
        });
    }

}

That all should work fine if the things you want to work with are subclasses of that base. If they aren't, you'll need a separate interface like BJSC mentioned above.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So you randomly decided to rename some of your own classes from code you wrote that was working just fine previously and you don't understand variable declaration well enough to use the new class names where needed? Seems a little odd to me, but hey, what do I know.

As I already said - getting it to a point it will compile is a good place to start. Then you can approach adding/removing from the array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Getting it to a state that it would even compile would help. You have all of your type declarations mangled up.

Did you write any of this code to begin with? If I were to guess, you're in the process of trying to rename variables and modify someone else's code and you don't understand it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would make the UI changes (ie the background color) in the itemStateChanged method (or actionPerformed would work too). The fireSelectionChanged() method is just responsible for notifying the registered listeners of the change.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Interesting, this isn't very important, but would that always make the return type void?

It would make the return type be the return type of the last method call in the chain. You have created an object and called a method on it. It's no different than calling a method on a reference to that object that was created previously.

Also, with implementing this interface, would I be able to get rid of my focus listeners and item listeners that I added previously?

I have left the checkbox in as I thought it was a good suggestion. I'm just wondering where setting the InfoObjects background would come into play with the interface. Would I add it in the fireSelectionChanged method?

You InfoObject panel is still going to need to respond to some event like checkbox action performed, mouse clicked, etc. to know when to fire the selection change.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have chained the constructor with the .add() call, so the end result is a return type of the add() function - which is void. Construct it first, then add the listener.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The declaration looks just fine to me with the exception of that spelling difference.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll also face problems importing those classes if they were compiled into packages and you have unpacked them into a different directory structure.

edit: Just to elaborate a bit, in the example BJSC posted above, the compiler would expect "OtherClass" to be found in a directory named "other".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JLabels would work as well. I agree with BJSC, it would be a lot easier to draw an image one time in an editor for each symbol than to render them from primitive ops with Graphics2D.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Bleh, I clicked the wrong box on the post above. Should have been a +1 :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Spelling? implements InfoSelectionlistener If your class implements that interface, then its reference can be passed as a parameter to a method expecting that type.

The non-public API warning thing is most likely a matter of how you declared the interface. You probably didn't declare it public, but it's being used in a public manner.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

just buy a black book

Thanks for that absolutely useless comment to dredge up this old thread, Ankit. I'm sure everyone appreciates your contribution.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi everyone....can you give me a complete design of a library system?

Nope.

And I think this thread's done.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I am unable to create it till now. please help me.

What? You probably need to rephrase the question in a new thread. This doesn't make sense as it's written.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You still have to render that doubleBufferImage to your component graphics context in your paintComponent(Graphics) method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That would probably depend on what programming language you are using...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you searched the forums for "final year project"?