server_crash 64 Postaholic

I'm wondering if the jvm has become corrupt or something.

server_crash 64 Postaholic

I don't know much about JCreator either..Never used it before, but it's compiling things that the command line doesn't, so I guess I'll have to stick to that for a while. My guess would also be that it uses a JVM that runs an older version.

server_crash 64 Postaholic

You should post a seperate thread, so that you don't distract away from this thread starter.

server_crash 64 Postaholic

What about a BufferedImage?

server_crash 64 Postaholic

I guess I was wrong. I've had enough of teachers...In my class, I have a crappy teacher, and the other students know nothing.

server_crash 64 Postaholic

I tried compiling with JCreator, and it worked....? So why would compiling at the command line, be any different from compiling with JCreator? I mean, don't they use the same thing ?

server_crash 64 Postaholic

I rewrote it, but you really need to work on your conventions: indenting, and naming.

import java.io.*;

  public class Slope
  {
     public static void main(String args [ ]) {
     
     	double y2, y1, x2, x1;
 	y2 =0;
	y1 =0;
	x2 =0;
	x1 =0;

	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

	try 
	{
		System.out.print("\nY2 =");
		y2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("Y1 = ");
		y1 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X2 = ");
		x2 = Double.parseDouble(reader.readLine( ));
		
		System.out.print("X1 = ");
		x1 = Double.parseDouble(reader.readLine( ));
		
		reader.close ( );
	}
	catch (IOException ioe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	catch (NumberFormatException nfe) 
	{
		System.out.println("An error accoured while calculating this equation try again");
	}
	
	System.out.println( "The slope is " + getSlope(y2,y1,x2,x1));
   }
   
   public static double getSlope(double y1, double y2, double x1, double x2)
	{
		double yValue = y2-y1;
		double xValue = x2-x1;
		double slope = yValue/xValue;
		
		return slope;
	}
}
server_crash 64 Postaholic

I have this problem with graphics, actually I know it's with my compiler... If I try to set the background of a button or something I get erros that's not even in my code..

I have this:

btnCalc.setBackground(Color.blue);

and I get theses errors

//g is already defined
Graphics g = new Graphics();
 
//Graphics is abstract
Graphics g = new Graphics();
 
//variable yellow
g2d.setBackground(Color.yellow);

The weird thing is, I don't have those statements anywhere in my code. So does anyone know what's going on?

NOTE: This is not an applet, this is a JFrame.

server_crash 64 Postaholic

I plan on writing an app that will graph polynomial expressions. My question is, what should I draw the graph on? Should I just use the regular frame and use DrawLine(), or is there something like a bitmap, or canvas thing I should use?

server_crash 64 Postaholic

Ok, that was my second guess...
You have to use equals() to compare strings like you were wanting.

server_crash 64 Postaholic

I'm not sure I understand completely...So correct me if I'm wrong, when the user enters a specific key, such as "friends", you want to "spit" out the array corresponding to that array.

server_crash 64 Postaholic

Plus it's much easier to have a book in front of you, that you can search through and stuff...I mean at least I prefer a book much more than having to stare at my computer screen, and stuff.

server_crash 64 Postaholic

I would DEFINATELY go with the online course. This way you can learn more at your own pace, and it's much easier to teach yourself than have an instructor try to teach you. Also, about the mathmatics part, I'm not the best in math, but I'm pretty darn good at programming. You said you were a writer, this means you have excellent language skills, and in my opinion, this will help you much more. Actually, if you like the aspects of language, you will probably love programming.

server_crash 64 Postaholic

I don't think you can use the break statement in for loops. I guess you would have to set the count variable to something greater than the ending condition in the loop, that way it won't loop anymore.

for int(i=0; i<10; i++)
{
   if (i=2)
   {
       i = 11;
    }
}

or something like that;

server_crash 64 Postaholic

Sorry, I've never really worked with netbeans, so I don't know anything about setting the classpath on that...Maybe it's the same principle though:

try this:

GOTO: Start -->(right click on)My computer--> properties -->advanced

--environment variables

you should have one that says classpath and path:

set the path variable to the path that points to the bin folder located in your jdk folder

set the classpath variable to the path that points to the tools.jar file located in your jdk folder

Again, not sure if this will work. I don't use netbeans.

server_crash 64 Postaholic

You can dual boot. It's really easy, just create another partition while installing the linux distro.

server_crash 64 Postaholic

ohh, well if he's wanting to learn it for a hobby, then there is no point in taking classes.

server_crash 64 Postaholic

I think there is some method that takes an image, and creates an array of pixels out of it:

I think it's something like this:

int x = getPixels(Image);
server_crash 64 Postaholic

I see what your saying.. I myself learned tons from books and stuff, and I'm currently in ap computer science and know way more than my teacher, due to the studies I did outside of school. So, if I know all of this, why am I taking the class? I'm taking it to get credit for it. It's the same way with college, or online classes. You take them so you have proof that you know the stuff. What would happen if you fill out a resume for a job? You couldn't just put that you learned everything you know from books.

server_crash 64 Postaholic

Ohh I see what it is now, it's your classpath..Have you set it yet?


If you haven't set it to point directly to the tools.jar file

If you have, post it, and I will take a look at it.

server_crash 64 Postaholic

A class is not necessary? Do you want a job?

server_crash 64 Postaholic

The filename should have the same name as the class:

public class X

so the filename should be:

X.java

Is your filename HelloWorld.java ?

server_crash 64 Postaholic

I'll help you with the System.outs to get rid of the bulk of the problem, but I am very sick right now, or else I would help you fix all of it.

System.out.print("Cannot find specified item -" \' + item + \');

should be something like this"

System.out.print("Cannot find specified item -" + "\\" + item + "\\");

also, if you want to convert an int to a string, do it like this:

int index = Integer.parseInt(findItemIndex(item));

Sorry I can't help right now...

server_crash 64 Postaholic

Hope you don't mind me suggesting one, but this tutorial worked great for me...It's a little old, but very good.

http://chortle.ccsu.ctstateu.edu/CS151/cs151java.html

server_crash 64 Postaholic

Of course it is, but you can't learn everything from a class. So, I would recommend outside study's while taking the class.

server_crash 64 Postaholic

My guess is that your school uses some new packaged classes because they are too lazy to create a one line statement that reads input. EasyReader is not a java class, that is, if you haven't downloaded that add on..

use this:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int x = br.readLine();

server_crash 64 Postaholic

turns them into lazy bastards

lol
:cheesy:

I agree though, you should of at least let him show a little effort..I mean even if it was a bunch of method and class stubs, at least it would have been some effort.

server_crash 64 Postaholic

are you wanting to add it to the textfield? If so, all you have to do is create a document from the textfield..

import these:

import javax.swing.undo.*;
import javax.swing.event.*;
import javax.swing.text.*;

add an UndoableEditListener

create an UndoManager as an instance variable

create a Document as an instance variable

then create the document and add the listener to it(That is if you want to add it to a textfield,this is the way I took it)

doc = (Document)txtDisplay.getDocument();
		doc.addUndoableEditListener(this);

undoable edit event stuff

public void undoableEditHappened(UndoableEditEvent uee)
	{
		undoManager.addEdit(uee.getEdit());
   	}

then do the undo and redo like this:

//don't need this method
	public void processUndo()
	{
		 try
		 {
			 /* call the UndoManagers undo method
			  */
			 undoManager.undo();
		 }
		 catch (CannotUndoException cre)
		 {
		 }

	}
server_crash 64 Postaholic

Of course, as long as you import the right statements.

server_crash 64 Postaholic

I haven't looked too much at the code, but I did notice that you used integers..This means there will be no decimal places, and it's possible that your results will turn out to be 0 because of that.

server_crash 64 Postaholic
JTextField.setHorizontalAlignment(JTextField.RIGHT);
server_crash 64 Postaholic

For the AP Comp. Sci. exam, we have to read 150 pages on this stupid program, and my teacher is wanting us to read the teacher's manual of it on the side..Which is another 130 pages...Now, I have heard that the questions on that case study makes up less than five percent of the test??? What is up with that?

server_crash 64 Postaholic

All you would have to do is change the code I gave you little bit...

server_crash 64 Postaholic

are you talking about something like this?

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x;
int count = 0;
int i;

do
{
   System.out.println("enter a number");
   i = Integer.parseInt(br.readLine());
   x = x + i;
   count ++;
 }
  while(i != -1);
  int b = x / count;
  System.out.println("Average is: " + b);

Don't exactly take my word for it, I'm doing this off the top of my head.

server_crash 64 Postaholic

I fixed it...Using JRadioButtonMenuItem worked..

server_crash 64 Postaholic

It's like 550 lines of code...but if you want it, you got it...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

import javax.swing.undo.*;
import javax.swing.event.*;
import javax.swing.text.*;

import java.text.*;

public class Calculator extends JFrame implements ActionListener, UndoableEditListener
{
	JMenuItem exit;
	JMenuItem clear;
	JMenuItem copy;
	JMenuItem paste;
	JMenuItem undo;
	JMenuItem redo;
	JMenuItem aboutCalc;

	JRadioButton rb0;
	JRadioButton rb2;
	JRadioButton rb4;
	JRadioButton rb6;
	JRadioButton rb8;

	
	JButton[] btnNums;
	JButton btnBack;
	JButton btnClear;
	JButton btnAddMem;
	JButton btnPasteMem;
	JButton btnCalculate;
	String[] strNames;
	String strOperand1;
	String strOperand2;
	double dOperand1;
	double answer;
	double memoryVar;
	int operatorCount = 0;

	final String STR_MULTIPLY = "MULTIPLY";
	final String STR_DIVIDE = "DIVIDE";
	final String STR_ADD = "ADD";
	final String STR_SUBTRACT = "SUBTRACT";
	final String STR_SQUARE = "SQUARE";

	String whichOperator;
	DecimalFormat dec;
	Document doc;
	
	
	JTextField txtDisplay;
	ArrayList operands;
	
	UndoManager undoManager;	
	public Calculator()
	{
		
		JPanel menuPanel = new JPanel();
		BorderLayout br = new BorderLayout();
		
		JMenuBar menuBar = new JMenuBar();
		
		JMenu fileMenu = new JMenu("File");
		fileMenu.add(exit = new JMenuItem("Exit"));
		exit.addActionListener(this);
		
		JMenu editMenu = new JMenu("Edit");
		editMenu.add(undo = new JMenuItem("Undo"));
		undo.addActionListener(this);
		editMenu.add(redo = new JMenuItem("Redo"));
		redo.addActionListener(this);
		editMenu.add(copy = new JMenuItem("AddM"));
		copy.addActionListener(this);
		editMenu.add(paste = new JMenuItem("PasteM"));
		paste.addActionListener(this);
		editMenu.add(clear = new JMenuItem("Clear"));
		clear.addActionListener(this);
		
		JMenu formatMenu = new JMenu("Format");
		ButtonGroup bg = new ButtonGroup();	
		rb0 = new JRadioButton("###",false);
		rb0.addActionListener(this);
		rb2 = new JRadioButton("###.##",true);	
		rb2.addActionListener(this);
		rb4 = new JRadioButton("###.####",false);
		rb4.addActionListener(this);	
		rb6 = new JRadioButton("###.######",false);
		rb6.addActionListener(this);
		
		bg.add(rb0);
		bg.add(rb2);
		bg.add(rb4);
		bg.add(rb6);
		formatMenu.add(rb0);
		formatMenu.add(rb2);
		formatMenu.add(rb4);
		formatMenu.add(rb6);
		
		JMenu aboutMenu = new JMenu("About");
		aboutMenu.add(aboutCalc = new JMenuItem("About Calculator"));
		aboutCalc.addActionListener(this);
		
		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		menuBar.add(formatMenu);
		menuBar.add(aboutMenu);
		setJMenuBar(menuBar);
		
		undoManager = new UndoManager();
		undoManager.setLimit(1500);
		
		
		/*  construct a JPanel and …
server_crash 64 Postaholic

I have a JMenu with some radio buttons...For some reason, when I click the stupid things, they won't do anything...and by that, I mean they want change their state to being clicked(as in the circle being filled)..It's like they are disabled...I'll post the snippets of code with them in it:

JMenu formatMenu = new JMenu("Format");
		ButtonGroup bg = new ButtonGroup();	
		rb0 = new JRadioButton("###",false);
		rb0.addActionListener(this);
		rb2 = new JRadioButton("###.##",true);	
		rb2.addActionListener(this);
		rb4 = new JRadioButton("###.####",false);
		rb4.addActionListener(this);	
		rb6 = new JRadioButton("###.######",false);
		rb6.addActionListener(this);
		
		bg.add(rb0);
		bg.add(rb2);
		bg.add(rb4);
		bg.add(rb6);
		formatMenu.add(rb0);
		formatMenu.add(rb2);
		formatMenu.add(rb4);
		formatMenu.add(rb6);

Why would I not be able to click these buttons?

server_crash 64 Postaholic

Thank you!

server_crash 64 Postaholic

Let's say I have two classes, Class1, and Class2.....
Class2 creates and instance of Class1 and calls one of it's methods like this:

Class 2
{
  Class1 c1  =new Class1();
   c1.myMethod();
}

Now, that would work...But, could you have just the class variable instead of the class instance variable like this:

Class 2
{
  Class1.myMethod();
 }

Or would that not work...What I was thinking, was in order to do that, Class1 would have to be static..Right?

server_crash 64 Postaholic

You can always set the foreground or background color of your panel or content pane...Or I think you could create a Font object.

server_crash 64 Postaholic

I think you would run into accesibilty issues there. I don't think applet are allowed to do that.

server_crash 64 Postaholic

I finally figured it out.. When I created the table, I specified the data type after the name of the field...I don't know how I could be that stupid(which is why I'm blaming my computer this time)... It did update the single test field like I wanted, but for some reason the same sql exception is being thrown. I guess it doesn't matter much now, but do you have any idea why it's still being thrown.

server_crash 64 Postaholic

I tried something like this:

System.out.println(statement1.executeUpdate(insert));

but it throws an sql exception saying simply "general error"

If I shouldn't use System.out for checking the return val, please let me know how I should be checking it.. I do have the code that created the table, so I could post that if you think it's something in effect to it..

server_crash 64 Postaholic

I tried that, but it's still not working. There's not exceptions thrown, and I made sure no DNS has the same name...I checked case sensitivity, and everything was correct..Did I enter everything correctly according to the data types?

Name is a String
ID_NUM is an int
Pay is an int

server_crash 64 Postaholic

I have the datasoure and drivers set up, but for some reason this code is not updating the database.

import java.sql.*;

public class TestCreateCoffeeTable
{
	public TestCreateCoffeeTable()
	{
	}
	public static void main(String[] args)
	{
	   try
	   {
		String createStatement;
		
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		
		String dataSource = "jdbc:odbc:Coffeebreak";
		
		Connection con = DriverManager.getConnection(dataSource);
		
		Statement statement1 = con.createStatement();
		
		[B]String insert;
		
		//add the info
		insert = "INSERT INTO Coffeebreak VALUES( 'Bob', 24, 23)";
		
		statement1.executeUpdate(insert);[/B]
		
	   }
	   catch(ClassNotFoundException cnfe)
	   {
		   System.err.println(cnfe);
	   }
	   catch(SQLException sqle)
	   {
		   System.err.println(sqle);
	   }
	   catch(Exception e)
	   {
		   System.err.println(e);
	   }
	}
}

I'm sure that the problem has to be with what's in bold, but it looks right...
I do have the code that created the table if you need that. It created three columns, Name, ID_NUM, and Pay...But none of those are being populated.

server_crash 64 Postaholic

you could always use this:

boolean equalsIgnoreCase(String anotherString);

server_crash 64 Postaholic

Hi everyone,

The new 1.5 seems to work well and i really like the new look and feel.
You should try it

Richard West

I've got it, and have been using it for a while. I was just wondering if anyone else uses it on a day to day basis.

server_crash 64 Postaholic

I wonder if this would work: Create one array with all the values you need, then create a gridlayout with the certain number of rows and columns you need and then append them to the container set to the grid layout

server_crash 64 Postaholic

You WON'T understand certain concept untill your very experienced with java. Polymorphism, inheritance, and other concepts like that aren't very difficult, but you just want grasp it starting out. I wouldn't even waste too much time looking at it, untill you have a good understanding of java, then it is very important that you study those topics. But, once you have a good understanding of the language you won't find it difficult.

server_crash 64 Postaholic

If you don't have to use the 'if' way, you could always throw them in an array and sort them

int[] nums = {a,b,c,d,e};

Arrays.sort(nums);
int x = nums.length;
System.out.println(nums[0] + " " + nums[x]);