server_crash 64 Postaholic

If you simply trying to replace one character like that, use the replace method:

class ReplaceAll
{
  public static void main(String[] args)
  {
	String s = "Replace /, /, and /";
	
	String replace = s.replace('/','r');

	
	System.out.println(replace);
  }
}
server_crash 64 Postaholic

I guess after you create the button, you would set the font of it:

JButton.setText("Button");
JButton.setFont(new Font("sansserif",Font.BOLD,12);

Don't know if that will work or not, doing it from memory.

server_crash 64 Postaholic

Thank you for replying, unfortunately this didn't work(Don't know why). I added the space between the :, and a blank line at the end. It still gave me an invalid header field when ran. You have anymore suggestions or thoughts about this?

server_crash 64 Postaholic

create your own costructor with those 3 arguments, it will give you a good learning experience! ;)

server_crash 64 Postaholic

Both java and anything in the .NET framework is very hot right now. I personally think they are the wave of the future, and any employer will be looking for people qualified in these areas.

server_crash 64 Postaholic

Now that I understand the question a little better, if not jwentings suggestion, what about a Math program that will solve almost any algebraic equation entered.

server_crash 64 Postaholic

Did you say you were getting paid for this? If so, you should have the experience to do it yourself.

server_crash 64 Postaholic

Yeah I tried that..I'm getting an invalid header error, and I've tried all sorts of combinations to see if I could get it to work..But, I did add the blank line at the end.

server_crash 64 Postaholic

New code --- Efficency

Modifying code -- improve efficency :mrgreen:

server_crash 64 Postaholic

I'm not sure if the array list would be the best way to go, but I could be wrong..Have you tried just creating an array of the Item Objects? But of course then you couldn't add extra items at runtime.

By the way, is this getStartValue() method going to return different results for each Item?

I mean, would each of these return different values:

double amount = itemsList[0].getStartValue();
double amount2 = itemsList[1].getStartValue();

server_crash 64 Postaholic

I would do something like this:

public void actionPerformed(ActionEvent ae)
{
  if (ae.getSource() == theCalculateButton)
  {
     int comp = Integer.parseInt(computerQuanityJTextField.getText());
     int print = Integer.parseInt(printerQuanityJTextField.getText());
     double tax = .175;
     totalJTextField.setText("" +getCost(comp,print,tax));
  }
}


public double getCost(int compQuanity, int printQuanity, double tax)
{
  double totalCost = compQuanity * 350;
  totalCost += printQuanity * 125;
  totalCost += totalCost * tax;
  
  return totalCost;
}

Although, I would use some constants for the Computer cost, the printer cost, and the tax.

By the way, very nice layout of your program.

server_crash 64 Postaholic

you can't do this:

public void paint(Graphics g) extends JLabel

this is a method extending?

second, you have to ovveride the paintComponent method, not paint();

I think it would be something like this:

public void paintComponent(Graphics g) {
   g.drawLine(x1,x2,y1,y1);
   JLabelName.paintComponent(g);
}

I'm not sure about the last line of the code, but It might work..

server_crash 64 Postaholic

I guess you're looking at Java courses?
Sun has excellent ones. Available as classroom study, web based, or CD/Book format depending on course and your preferences.

Ahhhhh, how could I forget the Sun site? Can't believe I didn't think of that..Thank you. I guess I won't even worry with the other site now.

server_crash 64 Postaholic

If you take it in succession like that, your score will of course go up, but that won't last for long. There will be a point when you score stops going up, even after taking it in succession like you have. So yes, the best thing is to study. If you feel like you are ready, grab a book on the java certification, and I think you'll be suprised at the knowledge that test requires(As I was).

Ghost commented: server crash was harsh and arrogant +0
server_crash 64 Postaholic

Should I put all of my classes in a package? I mean, is that what they meant, because I took it as I needed to create a whole new class, that only created an instance of the main one.

server_crash 64 Postaholic

Yeah, I was kind of thinking it was crap, because I finally found out how much they were: $2000 ---that's two thousand, not two hundred!

server_crash 64 Postaholic

Well, if you draw them don't you set the size and everything of them? Or are you worried about the layout manager screwing things up?

server_crash 64 Postaholic

Your not doing that right, but answer this: Do you have to draw on a label? I mean you wont get much of an area to draw on...A much better way, would be to create an external class that extends Canvas, and use that as your drawing surface..When you have the external class created, you would override the paintComponent method, not the paint() method. Once the external class is created, you would simply add it to the other main class. If you want to do it this way, I can help you a lot more.

server_crash 64 Postaholic

(you'll have to excuse me i don't even own a computer, i just keep read this stuff until i can afford one)?

Wow! if that is true, you are one dedicated person.

server_crash 64 Postaholic

Are you talking about not answering the curve part? Could you just drwa multiple lines making it appear to be a curve only being made up of line segments.

That's probably not a bad idea, although I would check out the drawArc() method first, and if that didn't work for him, then doing what you said certainly would.

server_crash 64 Postaholic

You can draw an arc in java, I guess that would be the same thing as a curve:

Somthing like... Graphics.drawArc(//code);

server_crash 64 Postaholic

ohhh Sorry dude, I thought you were like trying to insult my intelligence or something....Dang, I hate it when I do that...Really, I am sorry for being an a$$...please forgive me...

Anyways,

JLabel, is a component in swing...It's like any other label, in any other programming language..All it does is display information, and in matt's case, he's wanting to draw on top of the component...So, in order to do that, he has to override the paintComponent method...And no, it doesn't fully answer his question, it answers only part of it...I'll try answering the rest of it later...

Again, I'm really sorry..I thought you were trying to say that I didn't know what I was talking about! sorry :o

server_crash 64 Postaholic

textArea.setForeground(Color.blue);

There might be some mistakes in the Foreground part, I can't remember how to spell right now, nor which letters to capitalize.

server_crash 64 Postaholic

He said he wanted to draw some graphics on a JLabel, well that's how. Maybe you should think a little harder before posting stupid replys. Besides, if you didn't even know what I was talking about, why did you even post? It was obvious that helped...Now stop taking away from other people's posts.

server_crash 64 Postaholic

use paintComponent(Graphics g)

server_crash 64 Postaholic

Are you talking about setting bounds of the frame, or the 3D shapes your wanting to draw?

server_crash 64 Postaholic

C++, your parents must be rich or something...I know my dad would stomp my arse if I failed a $150 test.

server_crash 64 Postaholic

I read something that said the main class cannot contain any package statements....Is this true? If it is, that's my problem, because I import swing, awt, and all that good stuff.

server_crash 64 Postaholic

I've created a jar file like this:

jar cfmv Manifest.mf RoboPlot.jar RoboPlot.class ImagePlotter.class

The manifest.mf file looks like this:


Main-Class:RoboPlot

For some reason, when I use this command to run it,
java -jar RoboPlot.jar

it tells me that the main class could not be found

I also tried this:

Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class:RoboPlot

and it didn't work either.

server_crash 64 Postaholic

ahh just like the SAT!

server_crash 64 Postaholic

http://www.smartcertifydirect.com/

Has anyone ever come in contact with these, or know anything about them? I thought about taking one, but I don't know if they are worth it or not. Any feedback would be greatly appreciated.

server_crash 64 Postaholic

Plus asking others to do your homework is seriously frowned upon. Just don't do it.

lol, I was going to let him find that out when he posted in the java programming forum!

server_crash 64 Postaholic

So is the SCJD held in a higer regard than the SCJP?

The crazy thing was I had read about 3 or 4 books on java, and none of them taught what was on the practice exams! I mean, even some of the simple things like how many classes you can extend, and how many interfaces you can implement wasn't even in these books.

server_crash 64 Postaholic

You would get a lot more responses, if you chose to post this in the proper forum...If you look, this is the book review forum..Post it in the java programming forum, and I guarantee that you will get more responses.

server_crash 64 Postaholic

I'm planning on taking it, but NOT right now! I've studied for it about a year or so, and over the summer, I'm probably going to take a class on it. The java certification has to be one of the hardest out there(not that I would know), because those questions on practice questions are extremely hard..

Anyways, jwenting, good luck on the upcoming exam..I hope you pass! If you do, be sure to let us know.

server_crash 64 Postaholic

I thought there was a 12 year old that got certified?

server_crash 64 Postaholic

Thanks man, this program was a headache!

server_crash 64 Postaholic

I really don't know what to say; I bought a book on this a while back, and I have to say, those questions are VERY HARD!

server_crash 64 Postaholic

I had all of this program finished except for the plotting like a week ago...Ever since then, I've been trying to figure out how to plot the stupid polynomials..I thought I had it, but the program seems to go crazy whenever it's suppose to repaint..It's like repainting components on top of other panels and stuff..This program is in two seperate classes, it's pretty small...If you don't mind, see if you can't get this working properly, and make sure that I'm on the right track in trying to plot this thing.

Main Class

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

public class RoboPlot extends JFrame implements ChangeListener
{
	JSlider[] numberSlider1;
	
	JTabbedPane tabbedPane;
	
	int x4;
	int x3;
	int x2;
	int x1;
	int x0;
	
	ImagePlotter ip;
	
	
	public RoboPlot()
	{
		ip = new ImagePlotter();
		tabbedPane = new JTabbedPane();
		
		JPanel tab1Panel = new JPanel();
		tab1Panel.setBackground(Color.white);
		tabbedPane.addTab("Line 1", tab1Panel);
		
		int max = 20;
		int min = -20;
		int init = 0;
		
		numberSlider1 = new JSlider[5];
		JLabel[] lblCoef = new JLabel[5];
		int count = 4;
		for (int i=0; i<5;i++)
		{
			lblCoef[i] = new JLabel("     a(x)^" + count);
			count--;
			numberSlider1[i] = new JSlider(min, max, init);
			numberSlider1[i].setMajorTickSpacing(5);
			numberSlider1[i].setMinorTickSpacing(1);
			numberSlider1[i].setPaintLabels(true);
	        numberSlider1[i].setPaintTicks(true);
	        numberSlider1[i].setSnapToTicks(true);
	        numberSlider1[i].setBackground(Color.white);
	        numberSlider1[i].addChangeListener(this);
			tab1Panel.add(lblCoef[i]);
			
			tab1Panel.add(numberSlider1[i]);
		}		
	
		Container pane = getContentPane();
		pane.setLayout(new BorderLayout());
		setBackground(Color.white);
		pane.add(ip,BorderLayout.NORTH);
		pane.add(tabbedPane);
		setSize(300,620);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("RoboPlot");
		setContentPane(pane);
		setVisible(true);	
	
	}
	
	public void stateChanged(ChangeEvent e)
	{
		for (int i=0; i<numberSlider1.length; i++)
		{
			if (e.getSource() == numberSlider1[0])
			{
				x4 = numberSlider1[0].getValue();
				
				ip.x4 = x4;
				ip.fOfX(x4);
			}
			 else if (e.getSource() == numberSlider1[1])
			{
				x3 = numberSlider1[1].getValue();
				
				ip.x3 = x3;
				ip.fOfX(x3); …
server_crash 64 Postaholic

I could, but I know for a fact it's not the code. Maybe later I will, but right now I have school.

server_crash 64 Postaholic

you can store it in a double:

double x1 = Event.getX();

double y2 = Event.getY();

I don't know how you are going to tell if the first points were clicked unless you use a boolean...Like that boolean is set to true if the frst points are clicked, and then set to false..If that boolean is set to false, y would then store to the points in the second set of coordinates:

double x2 = Event.getX();
double y2 = Event.getY();

server_crash 64 Postaholic

There should be an Edit button for you, and as for deleting it, I guess you would need to ask a mod.

server_crash 64 Postaholic

In the MouseEvent's you can do this to get the location of the click:

Event.getX();

Event.getY();

That would help you with the coordinates of where the click happened, and where you should draw the line.

server_crash 64 Postaholic

Probably whatever is the most efficent...Like if you have a small program that could be accomplished with an iterative loop, it would NOT be good practice to use recursion.

server_crash 64 Postaholic

think you could post a little more code, and with code tags?

server_crash 64 Postaholic

If your using JCreator, I think this is your only solution: MINIMIZE!

server_crash 64 Postaholic

The elements of ID, mark or whatever have to be of the same type as what those arrays are...

String[] ID = new String[12];

int[] mark = new int[12];

server_crash 64 Postaholic

First of all, I would recommend putting some of that code in the constructor method, rather than the main methd:

public class TaxCalc extends JFrame implements ActionListener
{
   //instance variables up here
   // like the textfields so you can get the input
  [B] public TaxCalc()
   {
      // some code goes here
    }[/B]

  public void actionPerformed(ActionEvent ae)
  {
       //this is how you get the input in variable form
        [B]Integer i = Integer.parseInt(textField.getText());[/B]

        //set the variable to the text of another text field
        textFieldSalesAmount.setText(i + "");
   }
  public static void main(String[] args)
  {
    TaxCalc tc = new TaxCalc();
   }
}
server_crash 64 Postaholic

This class is suppose to create a JPanel with a bufferedimage to draw on..I instanstiate this class from the main driver class, and it shows up fine, but I can't draw anything on the image, or even set the background color of the jpanel.

Here is the class, see if anything is wrong please:

import java.awt.image.*;
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class ImagePlotter extends JPanel
{
	BufferedImage cartisianImage;
	Graphics2D g2d;
	
	public ImagePlotter()
	{
		setPreferredSize(new Dimension(200,200));
		setBackground(Color.white);
	}
	public void paintComponent(Graphics g)
	{
		g2d = (Graphics2D)g;
		
		int width = 300;
		int height = 300;
		
		cartisianImage = (BufferedImage)(this.createImage(width,height));
		Graphics2D gc = cartisianImage.createGraphics();
		
		gc.setColor(Color.green);
		 Rectangle2D.Double theRectangle = 
            new Rectangle2D.Double(
                                       0,0,200,200);

		gc.draw(theRectangle);
		
		super.paintComponent(gc);
	}
	
	public void drawPolynomialLine(int[] xPoints, int[] yPoints, int count)
	{
		g2d.drawPolyline(xPoints,yPoints, count);
		repaintComponent();
	}
	
	public void repaintComponent()
	{
		repaint();
	}
}
server_crash 64 Postaholic

Of course there is, and there is many ways of doing this.

x = 5;

/loop
//parse a string entered by a user
  if (inputedNumber < x || inputedNumber > x)
  {
    //inputedNumber = aNewValue
  }

//end loop