Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are really lucky, you can even get spam like this in your Private Messages right here, like I did :)

Dear,

I know that my message will come to you as a surprise since I don’t know you in person or meet with you before, but I am of the believe that you would be obliged to come to my assistance after hearing about my situation.

I was, until recently, a Medical student of the University of Abidjan, Ivory Coast

West Africa.I am the only child of late Mr Frederick Akaza. My father was a very wealthy cocoa merchant based in Abidjan, the economic capital of Ivory Coast.

He was poisoned to death by his business associates on one of their outing to discuss on a business last year. When my mother died on the October 1989, my father took me so special because I am motherless. Before the death of my father last year, in a private hospital here in Abidjan.

He secretly called me on his bed side and told me that he has a sum of US$ 9,500,000 left in account in a bank here in Abidjan, that he used my name for the next of kin in deposit of the fund. He also explained to me that it is because of this wealth that he was poisoned by his business associates.
1)I am honourably seeking your assistance to provide a bank account where this money will be transferred to.
2)You will …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
double d = 32.456;
System.out.println( (int)d );
System.out.println( d-(int)d );
peter_budo commented: Somebody please give him something complex, he is getting borred... ;) +7
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are probably getting into an infinite loop or recursion that creates a lot of new objects until it's out of heap space. Check your loop conditions or recursive calls and make sure they are terminating as they should.

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

Ok, this kind of goes in a much different direction than you started, but if you aren't committed to doing the entire thing with your own 2D graphics then leveraging Swing components to do some of the work for you will really reduce a lot of the complexity. This would allow you to concentrate more on the game itself and spend less time doing calculations for the graphics (area calcs, hit testing, etc).

I worked up this example that uses a grid of components that extend JLabel for the board and the "insertion row" (where the player hovers to drop a piece). These components do have custom painting code, but that is the only graphics work that needs to be done. If you are more interested in making the game work than learning the nuances of 2D graphics, I'd recommend going in this direction.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
import javax.swing.BorderFactory;
import javax.swing.JLabel;

public class Board extends javax.swing.JFrame {
    InsertPiece[] insertionRow;
    BoardPiece[][] board;
    
    Player currentPlayer;  // player for this turn
    
    static final int ROWS = 5;
    static final int COLS = 6;
    
    public Board() {
        initComponents();
        
        buildBoard();
        setSize(500,500);
        
        currentPlayer = new Player("Smilin Bob", Color.BLUE);
    }
    
    private void buildBoard(){
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx=0;
        gbc.gridy=0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weightx = 1;
        gbc.weighty = 1;
        
        // build the insertion row above the board
        insertionRow = new InsertPiece[COLS];
        for (int col=0; col<COLS; col++){
            insertionRow[col] = new InsertPiece(col); …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Scaling the transform does not reduce the size of the Image object itself.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And for that reason, you shouldn't ever throw exceptions from main().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This thread really belongs in one of the lounges. It has no bearing on Java at all.

And sanzillas near-incoherent rambling that interest or competence in programming is related to lack of interest in the opposite sex is just nonsense.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps if you could post a screen shot of the main screen with a bit of explanation of the component hierarchy it would help. I think you are probably making it more difficult on yourself than it needs to be, but without knowing a little more of the structure I can't recommend too much.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So are you now seeing the circle at all after you have added it to the panel? Note that your paintComponent() method is not actually using the class attributes to create the ellipse, just hard-coded values.

Is there any reason that CircleComponent needs to extend JComponent? You could simply have a draw(Graphics) method in the class which takes the graphics as a parameter (same as it does now) and have your panel's paintComponent() method just call draw() on your CircleComponent and pass along the Graphics reference. This is what I was indicating in the earlier post. You don't have to extend JComponent just to have a method that draws on a graphics context that you pass to it and then you wouldn't have to mess with adding unnecessary components to the panel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, you're doing something quite different than I assumed. I'm not sure how you are placing that component withing whatever container you're using, but the paintComponent() method will need to use the Graphics2D.draw(java.awt.Shape) method to render the ellipse

public void paintComponent(Graphics g)
    {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setColor (Color.red);
        playerCounter = new Ellipse2D.Double(30,30,30,30);
        g2d.draw(playerCounter);
    }

Your mouseMoved event will need to postion/size that component as needed in the container and then call repaint() for that container.

Edit: Post collision there, you figured out the Graphics2D part I see. How are you placing this component? It will have to be in a container of some sort for it to be rendered.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I assume CircleComponent provides a method to draw to a graphics context? Just creating an instance of CircleComponent won't do anything for you by itself. Painting operations for a component will occur in paintComponent(Graphics). This means that your paintComponent() method is going to need access to that CircleComponent object so it can call the appropriate method on it to render to the graphics context. Something like

CircleComponent circle;

public void paintComponent(Graphics g){
  if (circle != null{
    circle.draw(g);
  }
}

Your mouse move handler can then either create a new CircleComponent, or better yet, alter the properties on a single instance as needed, and call repaint()

//Show the counter appearing above the columns the mouse is over
if(xposcounter > leftxpos && xposcounter < rightxpos)
{
   //Load the circle
   circle = new CircleComponent();
    repaint();
 }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could, but what would the point be?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Integer.parseInt() was already explained. The real point is that there is no generic method to make "asu" an int. It is totally dependent upon how you need to encode the string and that is totally dependent on what you intend to use it for.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See comments in the code

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;

public class HeartLandHomeFinance2 extends JFrame {

    JPanel Panel;
    JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12, lb13, lb14,
      lb15, lb16, lb17, lb18, lb19, lb20, lb21, lb22, lb23, heading, lb24;
    JTextField jt1, jt2, jt3, jt4, jt5, jt6, jt7, jt8, jt9, jt10, jt11, jt12, jt13, jt14, jt15, jt16, jt18, jt17;
    JButton bt1, bt2;
    GridBagLayout gb;
    JScrollPane jscrollpane;
    GridBagConstraints gbc;
    JComboBox combo1, combo2, combo3, combo4, combo5, combo6;
    Connection con;
    PreparedStatement stat;
    Statement stmt;
    ResultSet rs;
    Font f;

    // this constructor was not valid - constructors don't have a return type
    // explicitlly stated, because they always return an instance of the class
    public HeartLandHomeFinance2() {
        // you don't need a new Frame here
        // your class is a JFrame
        // I moved the frame calls into createAndShowGUI() as well
        createAndShowGUI();
    }

    public void createAndShowGUI() {
        setTitle("Heart Land Home Finance");
        setDefaultLookAndFeelDecorated(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        Container contentPane = getContentPane();
        // you have to initialize gb before you make the setLayout call
        // you were using a null layout because gb was null
        gb = new GridBagLayout();

        Panel = new JPanel();
        Panel.setLayout(gb);
        Panel.setBackground(Color.RED);

        gbc = new GridBagConstraints();

        f = new Font("Monospaced", Font.BOLD, 24);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridwidth = 3;

        heading = new JLabel("Heart Land Home Finance");
        heading.setForeground(Color.black);
        heading.setFont(f);
        Panel.add(heading, gbc);

        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 5;

        lb1 = new JLabel("Please Fill All The Fields in CAPITAL LETTERS"); …
tactfulsaint commented: your gud +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

even if you write Integer.parsrInt("asu"); you will get Number format exception but if you write Integer.parseInt("197") it will give the number 197.

Of course, which is already mentioned. You are missing the entire point.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

97 is the byte value of 'a'. Your read() call just got a single byte and converted it to int.

In any case, it's irrelevant. Without a stated encoding expectation, "asu" cannot be converted to int. Integer.parseInt() will convert a valid integer string to an int value. If you want to convert some other string to an int, there are many different ways to do so, but they are specific encoding methods - not just a general api call or statement.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you read the posts above, it has already been answered.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use ( ! "hello".equals(someString) ) edit: Yes, same thing striker just posted :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If your Tomcat installation doesn't have that jar then yes you'll probably have to add it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

use the following code to convert any string to integer.
...

That is absolutely not the way to convert a String to an int.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to add the jar file to the Libraries for the project.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll need to add the jdbc driver jar to your project properties under Libraries. You can access those under the File menu or by right-clicking the project in the Projects window.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Narue has it right. New developers that do not have a significant amount of relative work experience are not just thrown into coding generally. Perhaps if there is a small piece of functionality that would not affect other dependencies within the code base, they may be assigned work on those, but debugging and documentation is by far the safest way for newcomers to gain an understanding of the code without risk to the development. Most real-world projects are orders of magnitude more complex than the typical projects and assignments that new developers have worked on. Getting a handle on that does take some time and it must be worked into without jeopardizing the productivity of the team and introducing problems.

... and having a blog is not going to change that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Making those variables "protected" would also allow subclasses to access them.

(Of course, that may lead to some design traps by locking your base class into a particular implementation, but I doubt you really have to worry about that in this case :) )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your method will need to traverse the sorted linked list and find the appropriate place to insert it. Then it's a standard insertion by updating the "next" pointers so that the previous item in the list points to the new one and the new one points to the next one.

As written, you are only attaching a node to the head and then moving the head, which is going to result in a list of one at all times unless you are using a circularly linked list (which I doubt is the case).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You do not "create" a group method at all. It is a method on the Matcher, which resulted from calling the matcher() method on the pattern with the text that you want to apply the pattern to. If the pattern matches, the group(int) method is used to access the data from the pattern's capturing groups (you pattern only has one, which is the "(.*)" part).

String line = "Last modified: Jan 11, 2007 8:10:05 PM GMT";

// compile the pattern to be used
Pattern lastModifiedPattern = Pattern.compile("Last modified: (.*)");
// obtain a Matcher for that pattern on the target text
Matcher lastModifiedMatcher = lastModifiedPattern.matcher(line);
// see if the pattern matches the text
if (lastModifiedMatcher.matches()){
    // get the data that matched certain portions of the pattern
    // in your case, this will be in group 1
    String thePieceYouWant = lastModifiedMatcher.group(1));
}

I would recommend reading the api docs for Pattern and Matcher carefully if you wish to understand the nuances of how this code works. Regex is very powerful and provides a lot of flexibility in parsing all kinds of data out of text, but with that comes a level of complexity that requires a bit of study.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course it does - because you are not calling the methods on the matcher you created, as per the example, and you need to obtain the matcher from the compiled pattern, not with Pattern.matcher().

You need to work through those errors. The compiler messages are pretty straightforward and you almost have it. This is just very basic debugging.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, does it compile? Have you tried to fix the errors? You nearly have it correct, but there are still some pieces of the example code that you have not quite gotten.

You would gain more by playing the "What about now?" game with the compiler and the program outputs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, good example. That's the general idea that I was referring to as well. Alterations to the data that is being rendered, whether it is positional info on primitives or BufferedImages, occurs in a separate thread or Timer component with calls to repaint(). The paint method itself just renders that data.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should update the image, repaint, and sleep in a separate thread or a Swing Timer. This animation tutorial might help:http://www.developer.com/java/article.php/893471
The important concept is that the AWT Event Queue needs to be allowed to repaint after you have altered the image.

CaffeineCoder commented: Very helpful, has good information to contribute. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might take a look at Java Media Framework

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

densman, do not hijack threads to ask unrelated questions. You need to make a new thread for this and you need to post the code that you have to start with. No one is going to just write it for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, not quite there yet, as I'm sure you noticed if you ran it. Look at the example code I posted with the Matcher. The portion of the match that you want to capture is returned by lastModifiedMatcher.group(1). Group(0) contains the entire text that match the pattern. Group(1) contains the first match group, which is what you want to isolate. Read the API doc on Matcher for more info, but in your case group(1) will return the piece you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't mention what language(s) you are comfortable with, but you should be able to find some tutorials on a simple neural network for something like optical character recognition. This could be a good starting point. They are often used for pattern recognition amongst other things. For other topics you can look into statistical machine learning
It's a very broad field as you have probably already seen, but these might give you a starting point to work from.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's somewhat dependent upon what "com.toedter.calendar.JDateChooser" returns when you call getDate() if nothing has been chosen. Does it return a null? A default date? If you were just checking for a valid date from a string you'd just catch the exception thrown by SimpleDateFormat.parse(). Since you're using some custom component to return the date though, you'll have to figure out what it's returning for no selection.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Exactly what portion of the nation thinks of the state as being 'all knowing'?

A portion who would essentially throw over any notion of limits on governmental powers to investigate and prosecute the "War on Terra" (spelling intentional).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I have no idea, since you didn't post any of that code here, and that has nothing to do with the question that you did ask.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

VernonDozier is correct, you'll have to read each line separately before attempting to parse its data. StringTokenizer is also considered a legacy class. You should use String.split() or java.util.regex classes instead. You'll need a regex pattern for either one, since your delimiter of ":" also appears in your time values and thus a simple delimeter of ":" will cause those values to get split up and you'll have to merge them back. The Pattern for each of your items is very simple, so either of these methods would work fine

String line = "Last modified: Jan 11, 2007 8:10:05 PM GMT";

// using regex Pattern and Matcher
Pattern lastModifiedPattern = Pattern.compile("Last modified: (.*)");
Matcher lastModifiedMatcher = lastModifiedPattern.matcher(line);
if (lastModifiedMatcher.matches()){
    System.out.println("result: "+lastModifiedMatcher.group(1));
}

// using String.split()
if (line.matches("Last modified: (.*)")){
    System.out.println("result: "+line.split("Last modified:")[1]);
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can do this easily with a Timer.

tactfulsaint commented: Your The Best +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Notice that the only difference in those pairs of methods is the direction of advance, +1 or -1. If you see that much duplication between methods, chances are you can make them one method. Consider how it might work if you defined

final static int LEFT = -1;
final static int RIGHT = 1;

and passed the direction to search as a parameter to a single method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try using an ActionListener for your buttons instead of MouseListener. The disabled buttons still receive the click event and you don't check whether the game is over. Also, add a repaint() call at the end or your Restart_Game method so the buttons refresh their appearance.

I didn't have time to go through the whole thing, so I'm not sure if the smile button behavior is also related to using mouse listener instead of action listener, but it might be.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

October surprise? Bah, old hat. October surrender! :p

Heh, thanks for the amusing dose of tinfoil-hattery.
Note the following in the Sun article that was linked from that post:

Dictatorships can only thrive if the population is in constant terror and convinced the state itself is all knowing.

Sounds about right for our current administration. ;)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

does anybody have a simple program for player play with comp. and use import Keyboard and Random only?

You should make a new thread if you have a question, and this is not even a comprehensible question. You'll want to restate it if you do make a thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Especially given that you said you read the forum rules regarding homework and choose to disregard them and beg someone to do the assignment for you - and you can't even trouble yourself to make an attempt at proper English (That mess you typed is from laziness, not lack of experience with English).

Perhaps it will be a learning experience for you. Good luck.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your code then, because the code you posted above does not have a single line that attempts to set the image and we can't read over your shoulder here.

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

Do you not have any class notes on simulated annealing? Why are you trying to write an algorithm you do not understand?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Write some code would be my advice on what to do next.