Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Exactly, so at some point providers stop supporting the old product that sucks in favor of the newer one which is better (or perhaps just sucks less, in the case of IE7) and those few who cling to the old product either make the switch or accept the narrowing applicability of that product.

So really, to address The Dude's dissatisfaction with technological progress:
Upgrade or quit whining and deal with the fact that you can't access some new stuff with the old piece of crap you insist on keeping.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No reason to cut out IE6 when most still use it!!

No reason to cut out rotary telephones, when most still have them...
No reason to cut out 8-track tapes, when most still have them...
No reason to cut out VHS, when most still have them...

(There's a subtle pattern there. See if you can spot it.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

*sigh*
:yawn:

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It splits on a particular expression, which in your case should be tab, and returns an array of the pieces. If you want the second section then you just need the second element of that array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Really? Because this particular part would seem to be clearly saying something else

Returns:
the array of strings computed by splitting this string around matches of the given regular expression

Notice the array part.

(Also, there does not appear to be anyone named "u" here at the moment. Use proper English.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, perhaps you should post that line then, because personally I don't want to spend time counting down 40 lines in all that code that you posted (and it's doubtful that anyone else does either).
And read carefully the description of the error - it's pretty straightforward.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you read the api doc on split() at all?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then use String.split() to separate it and read the second element of the result.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, take a look at line 40, since that is where the error is occurring.

at BoardCreator.<init>(BoardCreator.java:40)

.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That depends what "second section" means. If you can't be more specific than that, you have little chance of getting a program to do something with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Heh,idiots dont support IE6 ....

Fail........

Using IE6: Fail

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I guess you didn't read this announcement at the top of the forum: http://www.daniweb.com/forums/announcement51-58.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

We use the Jakarta POI API for that here at work.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And "I'm confused about..." isn't very specific for a question. I doubt many people want to trace through the entire thing to try and guess what part you are confused about.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

522

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No thanks.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Assuming this is in a GUI, set the background color of one of your components to that color. You could create a JLabel for that purpose, or just use the background of your existing frame/panel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

518

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, building a bit on the LoginFrame code above, here is a tiny framework that manages a login frame and a main app frame that is shown for a valid user. It doesn't do much, but should illustrate the point a bit.

I threw the other classes in at the bottom so it could be pasted into and run from a single file. Obviously, you would want to separate them to appropriate top-level public classes.

The only valid login is "Bob","12345". (And don't take this to be an example of managing secure logins, the MainApp controller is the point of the code :P )

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginFrame extends JFrame {

    private Dimension dimLF = new Dimension(250, 200);
    LoginPanel loginJP;
    ErrorPanel errJP;
    
    MainApp mainApp;

    public LoginFrame(MainApp mainApp) {
        super();
        this.mainApp = mainApp;
        
        setTitle("BMS - Login");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new GridBagLayout());

        GridBagConstraints gbc = new GridBagConstraints();

        loginJP = new LoginPanel();
        gbc.gridx = 0;
        gbc.gridy = 1;
        getContentPane().add(loginJP, gbc);

        errJP = new ErrorPanel();
        gbc.gridx = 0;
        gbc.gridy = 0;
        getContentPane().add(errJP, gbc);

        setSize(dimLF);

        setResizable(false);
        setVisible(true);

    }

    class LoginPanel extends JPanel {
        LoginCredentials credentials;
        final JTextField usrTF;
        final JPasswordField passPF;
        
        public LoginPanel() {
            setLayout(new GridBagLayout());

            GridBagConstraints gbc = new GridBagConstraints();
            
            JPanel usrPanel = new JPanel();
            JLabel usrLabel = new JLabel("Username:");
            usrTF = new JTextField(10);
            usrTF.setToolTipText("Please enter your username.");
            usrPanel.add(usrLabel);
            usrPanel.add(usrTF);

            JPanel passPanel = new JPanel();
            JLabel passLabel = …
jasimp commented: What would the Java forum be without you? +9
peter_budo commented: Another great example +12
Alex Edwards commented: You're a hero. +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A separate controlling class to handle those transitions is cleaner to manage. The frames themselves are just visual mechanisms for interacting with the data/process, so it's really just data or state information that needs to be passed to the new frame (or a reference to the aforementioned controlling class that is actually controlling the process state).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You really should change

System.out.println("error");

to

e.printStackTrace();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

522

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, I can't fiddle around with your exact code, because there were several parts that weren't in all that was posted above. A couple things come to mind though. First, it looks like you're sharing a single GridBagLayout manager ("gbag") among several panels, but using as if each was separate. That could definitely cause unexpected results.

On the sizing issue, Swing won't resize your JFrame by default if it's contents change size. You would need to use setSize() or pack() to resize that top-level window.

I think you would have an easier time managing all of those components if you separated the panels into their own classes, a bit like this

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginFrame extends JFrame {

    private Dimension dimLF = new Dimension(250, 200);
    LoginPanel loginJP;
    ErrorPanel errJP;

    public LoginFrame() {
        setTitle("BMS - Login");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new GridBagLayout());

        GridBagConstraints gbc = new GridBagConstraints();

        loginJP = new LoginPanel();
        gbc.gridx = 0;
        gbc.gridy = 1;
        getContentPane().add(loginJP, gbc);

        errJP = new ErrorPanel();
        gbc.gridx = 0;
        gbc.gridy = 0;
        getContentPane().add(errJP, gbc);

        setSize(dimLF);

        setResizable(false);
        setVisible(true);

    }

    /** one panel for login components */
    class LoginPanel extends JPanel {

        public LoginPanel() {
            setLayout(new GridBagLayout());

            GridBagConstraints gbc = new GridBagConstraints();
            
            // probably don't need separate panels for each pair here
            JPanel usrPanel = new JPanel();
            JLabel usrLabel = new JLabel("Username:");
            JTextField usrTF = new JTextField(10);
            usrTF.setToolTipText("Please enter your username."); …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to take a look at this section of the Sun tutorial on using tables: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#validtext

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the "loginJP" and "errJP" classes as well. Preferably with just their UI component setup portions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you added the items as Integer objects:

int selectedValue = ((Integer)comboBox.getSelectedItem()).intValue();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your add() call here

particlePanel.add(new Particle(5,3E-26,rand));

is adding a Particle component to the panel itself. It actually needs to add that Particle to the "particles" list which the panel uses to manage the particles. Add a method

public void addParticle(Particle p )

to the ParticlePanel class, which adds that particle to the list.

edit: Also, Particle doesn't really need to extend JComponent. It doesn't depend on any of that functionality and it's just adding baggage to your Particle class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There are literally thousand of discussions on this to be found: http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=c%2B%2B+vs+java

The objectivity of the comparisons vary greatly from side-by-side feature listings to all-out religious flamewars. The truth can be found somewhere in between. The wiki entry on it is probably a decent starting point to wade in: http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You didn't get a lot of detailed help because you didn't show the least bit of effort to understand or complete the assignment yourself. Perhaps if you had posted even one specific question that demonstrated that you had tried understanding anything about it whatsoever, you might have gotten a bit more assistance.

But thanks for posting an absolutely useless example of "How to program Java procedurally and ignore the entire point of an object-oriented language" though. I'm sure it will help many new students learn how not to use Java.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Check the API on handleEvent(). It specifies the replacement. It's basically been out of date since JDK 1.1.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, basically all you need to is give your ToolbarWindow a reference to the Painter applet so it has a way to call back on it. The toolbar frame has absolutely no need for a reference to the applets graphics context. Here's your code modified just a bit with a clear() method added to the applet and the toolbar now taking a reference to the applet in it's constructor. I've bolded certain changes so they stand out:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Painter extends Applet {

    Color a = new Color(255, 100, 100);
    int xValue = -10, yValue = -10;
    ToolBarWindow TBW;

    public void init() {
        [B]// pass ref to ToolBarWindow
        TBW = new ToolBarWindow(this);[/B]
        TBW.setVisible(true);
    }

    public void stop() {
        TBW.setVisible(false);
    }

    public void start() {
        TBW.setVisible(true);
    }

    public void paint(Graphics g) {
        g.drawString("Drag the mouse to draw", 10, 20);
        g.setColor(TBW.GetCurrentColor());
        g.fillOval(xValue, yValue, 4, 4);
    }
    //Override Component class update method to allow all ovals
    // to remain on the screen by not clearing the background
    public void update(Graphics g) {
        paint(g);
    }

    [B]// added method to clear the applet
    public void clear() {
        Graphics g = getGraphics();
        g.clearRect(0, 0, getWidth(), getHeight());
        g.drawString("Drag the mouse to draw", 10, 20);
        g.dispose();
    }[/B]

    public boolean mouseDrag(Event evtObj, int x, int y) {
        xValue = x;
        yValue = y;
        repaint();
        return true;
    }
}

class ToolBarWindow extends Frame {

    CheckboxGroup cbg;
    Checkbox Red;
    Checkbox Black;
    Checkbox Green;
    Checkbox Blue;
    Checkbox Yellow;
    Checkbox Magenta;
    Button Clear;
    
    [B]Painter …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sounds like you better review your course notes pretty quickly, since no one here is going to do your homework for you unless you post your code and specific questions about what you're having trouble with.
(I'm guessing you don't have any code written yet).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to start with the wiki for Hash table and go from there as needed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, we use it for some scatter plot and bar charts. There are many built-in graph types for various data series. Look through the demo jar that accompanies the download for a lot of examples of the various charts.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps, if you demonstrate that you have made some effort on it. Post your code and ask specific questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Once again: take a look at JFreeChart.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, go figure:

line = br.readLine();
matrix[i][j] = line;

If you put the whole line in there, that's what you're going to get.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

518!
:P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I know they have done wrong but isnt this a little too intrusive?? (Maps right to thier house)

If you feel it's intrusive, why are you spreading the link around?

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

Nah, it's not really that hard if you're insane, as the results are likely to be insane as well - but you won't mind... because you're insane...

Rashakil Fol commented: Ok, I think you win the thread. +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

518

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The size parameters for Ellipse2D specify the bounding box by width(w) and height(h), thus they are twice the radius of your circle.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JFreeChart has some charts such as that, but as already mentioned, you have to understand what you're charting to make much use of them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think some slight modifications to your design could make things much easier. You may want to consider something like this as a starting point

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Brownian {

    public static void main(String[] args) {
        JFrame box = new JFrame();
        Container background = box.getContentPane();
        background.setBackground(new Color(255, 250, 202));
        box.setSize(700, 700);
        box.setTitle("Browniand Motion.");
        box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        ParticlePanel particlePanel = new ParticlePanel();
        box.add(particlePanel);
        box.setVisible(true);

        Timer mover = new Timer(25, particlePanel);

        mover.start();

    }
}

/** This panel serves as the container for your Particle objects */
class ParticlePanel extends JPanel implements ActionListener {

    List<Particle> particles = new ArrayList<Particle>();

    public ParticlePanel() {
        super();
        // add a particle
        particles.add(new Particle());
        // this is all you need to add another
        particles.add(new Particle());
    }

    /** invoked by the Timer callback */
    public void actionPerformed(ActionEvent event) {
        for (Particle p : particles) {
            p.updatePosition();
        }
        repaint();
    }

    public void paintComponent(Graphics g) {
        // clear the panel
        g.clearRect(0, 0, getWidth(), getHeight());
        // render each particle
        for (Particle p : particles) {
            p.render(g);
        }
    }
}

/** This class now just deals with the specifics of 
 * a particle itself. It doesn't need to know anything 
 * about listeners or the container.
 */
class Particle {

    public Particle() {
        rand = new Random();
        // You could pass these as parameters here if you want to
        // randomize the location and size when you create them. …
coveredinflies commented: Thanks very nice of you! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I just ran the code here. You also need to set 'radius'. It's currently zero. I changed this in your constructor

public Particle()
{
    rand = new Random();
    xcentre = rand.nextDouble()*600;
    ycentre = rand.nextDouble()*600;
    radius = 15;
    System.out.println(xcentre);
    particle = new Ellipse2D.Double(xcentre, ycentre, radius*2, radius*2);
}

and it works fine (assuming you changed the timer listener parameter to 'particle')

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Does this mean it doesn't update the particle I made earlier but this 'listener' particle?
Yes. Add the one that you already created, since that is the one you want the timer to call on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because that is the toString() representation of an ArrayList, which is what you are printing.

If you want to show it differently then iterate each list and print it as you see fit.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I couldn't speak to Groovy, but it's fairly straightforward to write a List to a file

try {
    List<String> someList = new ArrayList<String>();
    // obviously you would want to use a list with stuff in it
    BufferedWriter out = new BufferedWriter(
      new FileWriter("outfilename"));
    for (String item : someList){
        out.write(item);
        out.newLine();
    }
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}