Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This line

poly3.addPoly(poly1,poly2);

will return the result of adding the two parameters - but you aren't storing that result in anything.
To use the result you would use the function like so

Polynomial result = Polynomial.addPoly(poly1,poly2);

and you would then want to print that result.
(Note the different syntax for calling a static method. You use the class name - not an instance.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class LinePanel2 extends JPanel {

    Timer animationTimer;
    int lineLen = 50;   // length of the line
    int x = 65;    // x anchor
    int y = 65;    // y anchor
    float angle = 0f;   // angle of the line
    double angleChange = Math.PI/20;    // rotation per tick

    public LinePanel2() {
        // start the timer firing every 50ms
        animationTimer = new Timer(50, new LineAnimation());
        animationTimer.start();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        // this just makes the line look smoother, less pixelation when at an angle
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        // calc the x and y offsets based on the current angle and line length
        double dx = Math.cos(angle) * lineLen;
        double dy = Math.sin(angle) * lineLen;
        // clear the area and draw the line
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.setColor(Color.BLUE);
        g2d.drawLine(x, y, (int)(x + dx), (int)(y - dy));
    }

    class LineAnimation implements ActionListener {
        // this gets called every "tick" of the timer
        public void actionPerformed(ActionEvent e) {
            // change angle and repaint
            // subtracting for clockwise motion
            angle -= angleChange;
            repaint();
        }
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new LinePanel2());
        f.setBounds(100, 100, 200, 200);
        f.setVisible(true);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here's something to play with

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class LinePanel extends JPanel {

    Timer animationTimer;
    float angle = 0f;
    int lineLen = 60;
    int x = 20;
    int y = 20;
    int moveX = 2;
    int moveY = 2;
    double angleChange = Math.PI/20;

    public LinePanel() {
        animationTimer = new Timer(50, new LineAnimation());
        animationTimer.start();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        double dx = Math.cos(angle) * lineLen;
        double dy = Math.sin(angle) * lineLen;
        g2d.clearRect(0, 0, getWidth(), getHeight());
        g2d.setColor(Color.BLUE);
        g2d.drawLine((int)(x - dx), (int)(y + dy), (int)(x + dx), (int)(y - dy));
    }

    class LineAnimation implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            angle += angleChange;
            x += moveX;
            y += moveY;
            if (x < 0 || x > getWidth()) {
                moveX *= -1;
                angleChange *= -1;
            }
            if (y < 0 || y > getHeight()) {
                moveY *= -1;
                angleChange *= -1;
            }
            repaint();
        }
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new LinePanel());
        f.setBounds(100, 100, 300, 300);
        f.setVisible(true);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, not as a language feature. Many editors have tags for collapsing section of code though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>How would I grab the information located on the jPanel that I want to display on the second monitor? (is there a quick easy way to duplicate the panel)
I've put together a small example of how you might do that below. Perhaps it will give you a starting point.

>Would I encounter issues with the fonts? (Seeing as the second monitor will be much larger than the original one)
Yes, if you're using an enlarged image you will have pixellation effects.

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PanelCopyTest extends javax.swing.JFrame {
    /** Mirror image panel - see class def below */
    ImagePanel imgPanel;

    public PanelCopyTest() {
        initComponents();
    }

    /** blah blah, ui setup */
    private void initComponents() {

        panMain = new javax.swing.JPanel();
        txt = new javax.swing.JTextField();
        btnCopy = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panMain.setLayout(new java.awt.BorderLayout());

        txt.setText("Stuff");
        panMain.add(txt, java.awt.BorderLayout.CENTER);

        btnCopy.setText("Copy");
        btnCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCopyActionPerformed(evt);
            }
        });
        panMain.add(btnCopy, java.awt.BorderLayout.SOUTH);

        getContentPane().add(panMain, java.awt.BorderLayout.CENTER);

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

     /** This is where the relevant stuff occurs */
    private void btnCopyActionPerformed(java.awt.event.ActionEvent evt) {
        if (imgPanel==null){
            // first time set up the mirror panel
            imgPanel = new ImagePanel();
            JFrame f = new JFrame();
            f.add(imgPanel);
            f.setBounds(0,0,getWidth(), getHeight());
            f.setVisible(true);
        }
        // create a buffered image to draw the source panel onto
        BufferedImage imgCopy = new BufferedImage(panMain.getWidth(), 
                panMain.getHeight(), BufferedImage.TYPE_INT_RGB);
        // paint the source panel onto the image 
        panMain.paintComponents(imgCopy.getGraphics());
        // push it to the mirroring panel
        imgPanel.setImage(imgCopy);
        imgPanel.repaint();
    }

    /** Simple panel that displays an image */
    class ImagePanel …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, I was trying to steer him towards figuring that out for himself... :icon_rolleyes:

BestJewSinceJC commented: haha. shafted. +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your "Step 6" will do a little more than what you noted. See if you can spot it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It depends somewhat on how your video card(s) are representing the screen devices to the system. You can get the bounds of a GraphicsConfiguration to determine where it is in your graphics space. If your monitors are returned as separate devices, you can figure out where the bounds of each are and where you need to put your components.

On my current system with three monitors, getScreenDevices() returns a single device with bounds that span the total area of all three - so to position something on the third one all I can really do is figure x0=2*width/3. Your system may be different and return each monitor as a separate device, each with it's own bounds.

It will likely take you a bit of experimentation and examination of what info your system is returning to nail down exactly how to isolate your target area.

KirkPatrick commented: Glad to see there are people around here who are willing to explain things that are difficult to comprehend from the documentation. It is members like you that make communties/forums an enjoyable place. Thanks bud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the GraphicsEnvironment API. You can get the available screen devices with the following

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();

The GraphicsDevice class has a multi-screen example in the class documentation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'd recommend starting with How To Use Menus in the Swing tutorial.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code above will still not print the actual original list if it contains 10s because you are never adding the 10s to the array at all.

You need to add every number to the array. Then loop and print it.
Then count your 10s and print the count.
Then print the list, skipping the entries that are 10 - your instructions don't say that you actually have to remove the values, just don't print them. If you do want to remove the 10s, set the element to 0 or -1 or something.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, your second JFrame probably has a call to setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) somewhere in its setup code. You need to change that to use DISPOSE_ON_CLOSE or something else. Those are not commands. They are constants you use to specify the parameter value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yeah, stack traces from the event queue can be quite long and messy like that. Somewhere in all of that will be a line that tells the actual exception.

Anyway, one thing that I did notice is that you're calling setComponentZOrder() on the Card class, when it is the container holding the Card that you need to make the call on. Also, I'm not sure what the value of "TOP" is, but you want that index to be zero if you want that component on top of everything else in the container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm sure the stack trace says more than "something about an unknown source". It contains the exact error, the method that generated it, and the line number. It would help if you posted that here as well - at least the first couple of lines.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's because the entire expression GridBagConstraints.CENTER is the int constant value. Use the parameter directly

gridBagConstraints.anchor = c;
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What issues did you encounter? Yes, they are just ints and you should be able to pass them just like you have in the method signature you posted.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That depends on what database you are using. Generally there is a function that you can call to check the current value of a sequence. The next insert ID will be one higher - unless another transaction gets it first.

Unless there is a reason you can't, perhaps you should insert the row and get the ID prior to creating the folder.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

File > Project Properties > Libraries
Add the folder/jar/etc in the Compile tab.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you need to write tests that don't adhere to the access scope of the inner class? If it's not a static inner class, you should have an instance of the enclosing class to work from. If that's not the case, then perhaps your inner class should actually be a public top-level class?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to come with more than just "show me how to make this" though. Have you studied even the basics of using PHP? Do you know how to create an HTML form? Which parts do you have an idea of how to complete and which parts do you need more info on?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, perhaps you should post a question then?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can call setOpaque(false) on the brick panel if you'd like it to be transparent.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Great! :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should post some of the relevant code then. Your first post doesn't contain nearly enough information for anyone to help you out.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sounds like a question for whoever wrote your forum code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

sorry.. I don't know how to use code tags..

Well, read this then: http://www.daniweb.com/forums/announcement9-3.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"That's amazing. I've got the same combination on my luggage!" - President Skroob

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just pick one that you think could be useful for a small piece of your interface:
http://java.sun.com/docs/books/tutorial/uiswing/components/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can place them wherever you want just as with any other container. How you do that will depend on which LayoutManager you set for the panel.
Laying Out Components Within A Container

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Add the panel to the applet and then add the other components to that panel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can subclass JPanel to paint your image as it's background. Anything else you put on that panel should show up normally.

class ImagePanel extends JPanel {

        Image img;

        public ImagePanel() {
            super();
            img = new ImageIcon(getClass().getResource("images/blackX.gif")).getImage();
        }

        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
        }
    }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hi i have gone through u r code its good but not the best u can declare the variable in main instead of another n use it as an global and more often access specifiers are differently used in this n if u want u can look at dynamic billboard

No, just no. Suggesting the use of a "global variable" from main.java is probably the worst way possible to go about it. And you need to read this as well: http://www.daniweb.com/forums/faq.php?faq=daniweb_policies#faq_keep_it_clean

All that is needed is a public method on the "open" class that returns the data you want to display: open.getTheText()

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

dispose() does not destroy an object, it releases any native graphical resources related to the display of that component. It will have no effect on those references that you have stored in your board array. That is why you need to put in some cleanup code when the board closes that notifies the main controller to drop the reference. To make sure it gets called no matter how the user closes the frame, a frame listener is probably your best bet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> can you even call isVisible() on spots in teh array that were never initialized in the first place?
You would have to put in a null check first, but since if() statements short-circuit on failure, it could still be one statement

if( boards[1]!=null  && ! boards[1].isVisible() ){

I would recommend removing the dead references though. I'd also recommend using a List instead of an array to hold the board refs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could add an InternalFrameListener with code in the closing() function to notify your main class to remove the reference to it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is a forum for JSP.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It just depends on how the users will work with the separate panels. With tabs, all will be layered on the screen and only one can be active at any one time, whereas with the internal frames you can show as many or as few of the collection as you wish and they can be arranged in any manner you choose to view simultaneously.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, just found that the focus listener works if you add

internalFrame.setFocusable(true);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try using an InternalFrameAdapter instead of FocusAdapter. JInternalFrames don't generate the same events as regular frames.
http://java.sun.com/docs/books/tutorial/uiswing/events/internalframelistener.html

Using the activate and deactivate events should work for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is a small red triangle icon with an exclamation point in the right hand side of the title of the message that lets you report a PM.

If the user is already banned there really isn't a need to report them though, as they've already been handled.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

H2 is another good embedded database:
http://www.h2database.com/html/main.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>When you first visit DaniWeb, how do you begin your visit?
Sorry, late reply. I went out of town. I hit the User CP first as well, to check subscribed threads. After that, I keep an eye on Favorite Forums to see if new posts pop up. The fact that it was always visible while I was looking through other things was what made it so useful. As a mod, it's handy to be able to keep an eye on reported posts without having to go check some other page all the time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I understand you can't please everyone, however it's also worth considering 648,000 of the users you mentioned probably have less than 3 posts each, while the bulk of the answers to questions here come from less than 100 members - the vocal ones.

Many of us had to adjust our ways considerably with the last rounds of major changes. Having settled into new habits, it's frustrating to see a useful feature that we've settled into taken away.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I guess the regular users who have posted asking what happened to it and wanting it to be returned were not at that conference. I've seen 8 posts on it since it disappeared yesterday.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Cast your Graphics reference to Graphics2D and turn on anti-aliasing:

Graphics2D g2D = (Graphics2D)g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
kolibrizas commented: That really solves my issue! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those are actually unrelated to the painting example. That code just makes sure that the GUI initialization occurs on the event dispatch thread. You can read more about that here if you are curious:
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html

Stefano Mtangoo commented: Great piece of code, good explanations! +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's the minimal implementation of drawing lines on a JPanel. The important part is extending JPanel to override paintComponent() and use the Graphics reference to paint what you need to.

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);
        g.drawLine(0, 0, getWidth(), getHeight());
        g.drawLine(getWidth(), 0, 0, getHeight());
    }

    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);
            }
        });
    }
}

There is also a drawImage() method in the Graphics class.