JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Is SphericalCoordinate a kind of PolarCoordinate? If not, it shouldn't be a subclass. EndOf.
  2. Are there situations where you will use or accept a PolarCoordinate without worrying about whether it's cylindrical or spherical? If so, the common superclass will be useful
  3. Is there a useful amount of implementation detail that's common to spherical and cylindrical? If so a superclass could be useful
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no code there that displays anything. You have not written any code to display any output. So there is no output.

You forgot to write print statements such as

System.out.println("add: " + e.add(15,5));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are more than one ways to do this, but here's one:
Start with an ArrayList containing the numbers of the columns with no queen. Initially it will contain the numbers 1..8.
For each row, pick a column number from the ArrayList at random, place a queen at that row/col, remove that entry from the ArrayList (thus ensuring that you never place another queen in that column)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

hey man - if it looks difficult then just break it down into small steps and do one at a time. As long as you keep trying things you'll get it right in the end! You never fail until you stop trying... :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IMHO it's a mistake to see it as 9 3x3 blocks. That's no more valid or relevant than 9 x columns or 9 x rows. Treating any one of those as a special case will just lead to duplicate code (one code for the special case, one for the other cases).
I had a go at this some years ago, just for fun, and concluded that the best structure was a 9x9 grid of cells, and 29 instances of a Group class where each instance held a list of 9 cells (blocks, rows, cols or diagonals). That way checking for completeness, correctness etc can be implemented as methods in the Group class that you can call in a simple loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AWT was Sun's first try at a Java GUI and it wasn't very good. So in 1998 (yes, seventeen years ago) they released Swing to replace AWT. Since then all the development has been in Swing, which has got better and better, faster and faster, while AWT remains stuck in the 1990's. There's no way you should be using AWT today.

stultuske's sample code is correct, but is based on an old version of Java. With current Java you can simply say

JButton button = new JButton("TRY");
button.addActionListener(e -> button.setText("Whoops"));
stultuske commented: yah, still working with Java6 on my current project .. +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are doing a potentially slow database connect + SQL operation inside your actionPerformed - ie on the Swing Event Dispatch Thread. That's going to stop all GUI activity while the SQL is happening and lead to an apparent lack of responsivness on the screen.

You should a start a SwingWorker or other thread to perform the database activities, and return from the actionPerformed immediately.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have TWO login dialogs - one created in main (line 24), the other created in showLoginDialog() (line 72).
The line 24 one gets the action listener, but the line 72 one is the one that is displayed, and that has no action listener.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, something like that. You will need to deal with moving in the other 3 quadrants, of course, but you could set up a test that's up/right to confirm before doing the other 3 cases.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your speed is a constant then you can only make 0, 45, 90 degree movements. To get any other angles you will need to vary the speed.
Eg:

if
deltaX = distance to be moved in the x direction
deltaY = distance to be moved in the y direction

if deltaX > deltaY
go full speed in x direction
but speed in y direction must be slower, ie speed*(deltaY/deltaX)

( and v.v if deltaY > deltaX)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried calling getText() for your two JTextFields after the dialog has finished?

The simple pre-packaged dialogs in JOptionPane are just that - simple. The assumption for inputDialog is that there is one entry field and one value returned. For your two-value case you should create your own simple dialog and query the field contants via their getText() methods afer the user has pressed OK.

Start4me commented: Thank you very much, I appreciate your help +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Depends on the platform...
C# if Windows only
Swift if Apple only
Java if Linux or multi-platform

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because there are two different wrapping processes going on.
First you wrap the byte-oriented input stream in a character-oriented Reader, then you buffer those characters in a Buffered stream

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes it will work. The listener/send is executed on the Swing thread, so it could run concurrently with your receive thread receiving data from the server. That's why it would be best that any GUI update after server input is done via invokeLater.

All you are doing is replacing your thread that waits for console input with the Swing thread that waits for user GUI inoput. It's the same really.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

InputStream reads bytes one at a time - no character set processing and no buffering. It's the parent class for stream input, but rarely used becuase one of its subclasses is usually more appropriate (eg BufferedReader)

BufferedReader reads characters and buffers its input.

If your input is text, always use BufferedReader.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like you're trying to adapt a command-line interface, which doesn't fit so well with Swing.
In your action listeners for the GUI you can simply send the appropriate commands to the server - all you need is a reference to the socket output stream. If you're not doing command line input you can discard that whole scanner thread/loop.
When you receive input from the server, update the GUI. You;ll probably be OK doing that in the existing "from server" thread/loop, but ideally you'll store the data and use a SwingUtilities invokeLater to do the actual update.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please never just say "get an error". Always post the complete text of all your error messgaes, along with the actual lines of code they refer to.

Anyway, in tis case it's obvious. You forgot to initialise highest, leading to a null pointer exception (unless your compiler spotted it first)

Slavi commented: It's obvious for you* =]] +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you really think anyone will be interested in trying to decode such a horrible pile of opaque code? Meaningless variable names and no comments. It's also far longer and more repetitive than the solutions already posted.
Nice try, but no cigar.

peter_budo commented: Yeahhh, look like my code after first Java lecture +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IMHO that's the standard OK implementation for a simple application.
One would expect to see the middle layer consisting of (at least) a Dictionary class that holds a collections of DictionaryEntries, with methods that add or remove entries or change the collection itself. In the entry class I would expect all the methods that work with individual entries (eg formatting). SQL has no place here, that belongs in the data layer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Not always - it depends on the implementation of the list. For example a linked list has the same overhead for inserting an element in any specified position (indeed, if the implementation only keeps a ref to the head node then you have to search sequentially to get the end node, which gives it the highest overhead)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

divinity02 has started 38 threads in the Java forum over the last seven months and is still unwilling to ask sensible questions or post proper error messages. None of those threads has ever achieved "solved" status. Maybe we are all wasting our time here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Isn't android used on mobile devices? Aren't jdeveloper and eclipse development environments? How could this question possibly NOT be relevant to mobile development?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's really only justified where you need the absolute maximum performance, or you need to get very close to the hardware (eg device drivers). For anything else there are far more productive and easy languages (C#, Visual Basic, Objective C, swift, java, python, php, javascript, ruby etc etc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

*Which leads me to the question: was it this difficult in the 1960's and 1970's for Computer Scientists to create programs? *

Only if they were foolish enough to use C or C++ for application programming. Applications like yours would be straight forward in business-oriented languages like Cobol, PL/1, RPG etc. Yes, you need C or C++ if you need to deal with memory allocations and addresses etc, but for business applications these just add a layer of difficulty and error-proneness that isn't appropriate. <waits for flame>

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks to me like the data you are entering at runtime isn't what the program expects. Your new exception looks like Scanner's version of the oriogional exception, so it's the same underlying problem - eg maybe you are pressing enter multiple times after entering n1.
If you just enter the numbers separated by spaces or carriage returns then that code should run OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... that sounds like you are doing the right thing already.

Maybe this is just an example of "premature optimisation" - trying to fix a performance problem before you know that there is one?

Unless you're in some kind of expert corporate-scale development, the best advice is to get it working with sensible simple implementations first. Then, and only then, if there's a performance issue, identify exactly what/where it is before spending time making the code more complicated.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your enthusiasm and commitment are truely superb. I'm sure that you have the right attitude to achieve great things.
But in this case I agree that this total project is unrealistic, and could just demotivate you. Apple shipped the first versions of their voice command software in MacOS around 1996. Ten years and billions of dollars later it kind-of working OK with Siri, but still not that great. There's only so much one man can do.

Why not break it down into components, and just work on one of them for now. Maybe try the part that takes some input and parses it to understand what it means in terms of doing web searches or whatever. You can do that with simple typed input at first, and front-end it with voice recognition later, as a separate sub-project. (Or maybe collaborate with others to work on sub-projects in parallel.)

Yes, you want to do something amazing that will change the world. And I hope you succeed. All I'm saying is take it one step at a time and get some successful pieces completed one at a time so you can show progress and enjoy the rush you get when something works.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

code III has invalid syntax = it uses the method names without their ()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

By messing around with null layout and setBounds you are really wasting your time. Pixel positioning/sizing of components is useless in a world where screen resolutions go from 72dpi to over 400dpi.
Yes, there's a learning curve for layout managers, but there's no way to avoid them. Start here: https://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to fill a 300x400 window you will need much bigger sizes than 80x40

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's worth a try BUT...
== and != test for Objects being/not being exactly the same object (same address in memory).
You want to know if two different InetAddress objects represent the same IP address, for which you have to use their equals method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Oracle Java tutorials are always a good source of info
http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the relationship between the address and addressList Lists?
Are you sure that addressList contains all the entries you expect? Is the size() of address as large as you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As far as I know there are little or no changes to how Sockets or the NIO SocketChannel etc work from Java 7 to Java 8.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and it's not great code - obviously written by someone with limited Java skills, so it's not a good example to follow. (Even less a good piece of code to copy and claim as your own.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's it, just as I suspected.
Every time you execute paintComponent you get new random shapes.
To get the graphics for the file you call paint, which calls paintComponent...

It's always a mistake to change anything in paintComponent because it can be called at any time (eg when the window is re-sized). You should create a separate method to create new random shapes, and just paint the current shapes in paintComponent

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 62 is a terrible mistake.

You have a problem related to a file being written
In the code that writes the file you go out of your way to supress any exceptions and hide/discard any exception messages. You are saying "if anything goes wrong just pretend it didn't and keep going - don't bother me with it".

Nobody here is going to waste another second on ths until you put an e.printStackTrace(); in your catch block and run it a few more times.
(Maybe that's not where the problem is, but it's dumb not to eliminate it first.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you split the para by white space you will get an array of al the words, so each word will have its own array index (ignoring puncuation for the moment!).

You may have problems with the subsequent index numbers changing when you split add or remove words

iris91 commented: ok thanks for explaining, can you tell me how do i search by index? what's the syntax? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You cannot mix Data streams and Readers/Writers - they use completely different data formats. Data sttreams send (binary) data, readers/writers send text.
Either use a DataOutputStream to send data to a DataInputStream, or use a PrintWriter to send text to a BufferedReader

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are trying to define a method withiout finishing the previous method defintion. You canno define one method inside another method like that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JLabel does not display multi-line simple text.
You could use a JTextArea or somesuch, or you can use simple HTML formatting to display multi-line text in a JLabel

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If this seems a bit vague and ambiguous, then that's because it is. The technical differences between abstract and interface have been blurred even more in Java 8.
The best way to think about it is to look at the intent behind it.
If you want to define a contract that some classes can meet, then look at defining an interface. If there are multiple overlapping contracts then definitely use interfaces. eg Runnable, ActionListener, Serializable.
If you want to create a master template that other classes can use as a common standard base then define a abstract class. Eg Vehicle, RectangularShape

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just for a laugh I hacked this little program to help get the quad curves. Open the bitmap. Click 3 times to define a new curve (start/control/end points). Drag points as required. List of curves is printed after each change - you can change the format to make this more useful (eg print the actual code for a new quad curve ready to paste). Feel free to hack it yourself, it's only 200 lines
J

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * @author JamesCherrill
 */
public class CurveFitter {

    public static void main(String[] args) {
        new CurveFitter();
    }

    CurveFitter() {
        JFrame frame = new JFrame("Close this to exit application");
        frame.add(new FitterPanel(getImageFromFile()));
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    Image getImageFromFile() {
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(null);
        if (returnVal != JFileChooser.APPROVE_OPTION) {
            System.exit(-1);
        }
        BufferedImage image = null;
        try {
            File f = fc.getSelectedFile();
            image = ImageIO.read(f);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return image;
    }

    class FitterPanel extends JPanel {

        Image image;

        int pointCounter = 0;
        Point2D[] points = new Point2D[3];
        List<Point2D[]> curves = new ArrayList<>();

        Point2D[] selectedCurve = null;
        int selectedPointIndex = 0; // which point in selected curve

        FitterPanel(Image image) {
            this.image = image;
            ClickHandler listener = new ClickHandler();
            this.addMouseListener(listener);
            this.addMouseMotionListener(listener);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(image.getWidth(null), image.getHeight(null));
        } …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use String's charAt method to get individual chars. Wrap that in a simple loop to get all the chars one at a time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

:)

ps: Never NEVER NEVER do this when writing new code:

} catch (Exception e) {
}

If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
        public void paintComponent(Graphics g) {
            super.paintComponent(g);       
            g = graphic.getGraphics();
            g.drawImage(graphic,0,0,null);
        } 

You re-use the g variable on the third line here, thus losing your reference to the component's Graphics, so you draw the imge back onto iteself on the fourth line.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess your ChartFrame is a kind of JFrame - ie a top-level container or window, so you cannot place that inside a lower-level container like JPanel.

If you are usimg JFreeChart then you can replace your ChartFrame with a ChartPanel. ChartPanel is a kind of JPanel, and can be added to another JPanel without any problem.