BestJewSinceJC 700 Posting Maven

What amazes me is each and every company can save you hundreds by switching from one of the others. That basically means you sign up and the insurance company gives you a $300 check! Then you can switch again and get $700 from the new one. It's a really useful thing!

So true. And they also give you raised rates if you get in an accident regardless of fault as well as raised rates if you are young or male. . oh, and they are kind enough to throw in the lowest possible blue book value for your car if you happen to *need* them, i.e., make a claim. But it's fine if you keep dumping your money into them because hey - you have to, it's the law.

BestJewSinceJC 700 Posting Maven

Then you would just put this same exact statement:

int	integerInput = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the grade (0-100) or -1 to exit"));

into the while loop as well. And in the while loop, you would need to add your "integerInput" numbers into an int array. Kvass gave you basically all of the code. What are you confused about?

Look up how to use arrays in java, how to use while loops in java, and how to use for loops in java. Your teacher spelled out basically everything - his comments tell you what you need to do and the exact spot where you need to do it.

BestJewSinceJC 700 Posting Maven

White bread + mayo + mustard + turkey + yellow cheese slice

BestJewSinceJC 700 Posting Maven

It may be more complicated than I thought due to drawing JPanels which are components, perhaps the Swing Layout Manager is preventing you from explicitly setting the location and keeping it there. Maybe if you set the layout of the container to null it will work. But again, if you would post the *working, compiling* code instead of a snippet that doesn't come close to running then I could play around with it and truly help you. . anything else from me at this point is just speculation. If you can't post all of your code for whatever reason that is fine, hopefully someone else can help you. Oh, and what balmark says seems to be true, it only matters for constructors; in any other method, you can call super at any point.

BestJewSinceJC 700 Posting Maven

That is because the way you wrote it doesn't save any of the values after they are read in - in this section of code, you ignore the return value of showInputDialog, hence, you never store the value the user entered, and it is lost.

JOptionPane.showInputDialog(null, "Please enter the grade (0-100) or -1 to exit"));

Furthermore, your code is probably supposed to stop asking the user to input values if the user ever enters -1. But it doesn't do that. It only stops prompting the user for input values if they enter -1 on their first guess; whereas it should stop if they enter -1 for any of their guesses.

I think you should take a closer look at the code that kvass posted for you. Considering that it is correct. I don't see how your text pane could possibly report the correct values when you never stored them anywhere; in kvass's code, he stores the values in an array. If you use kvass's code and modify your text pane code so that it grabs the values from the array (using a for loop), then your text pane will work correctly.

BestJewSinceJC 700 Posting Maven

I don't know why your call to super.paintComponent(g) is the second call in your method; I was always taught that a call to super has to be the first call in your method as it says here. I could be wrong and this might be a special case, but I don't think so. And you don't need to be constantly adding the JPanel back; add it once, then simply clear the screen when you need to (which is what super.paintComponent(g) does if I remember correctly). Anyway, the code you gave me wouldn't compile or even come close, but this small sample works:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SectionPage extends JPanel implements MouseListener{
	JFrame tempComponent;
	boolean colorWhite;
	
	public static void main(String[] args){
		
		new SectionPage();
	}
	
	
	@Override
	protected void paintComponent(Graphics g) {
        super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		if (colorWhite){
		g2.setColor(Color.WHITE);
		} else g2.setColor(Color.BLACK);
        g2.fillRect(100, 100, 50, 50);
        
	}
        
    public void display( Graphics2D g ) {
    	
    }
    
	public SectionPage() {
		tempComponent = new JFrame("Test Graphics");
		tempComponent.add(this); 
		tempComponent.setSize(500,500);
		tempComponent.setVisible(true);
		this.addMouseListener(this);
		colorWhite=true;
        setBackground(Color.white);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		if (colorWhite) colorWhite=false;
		else colorWhite=true;
		repaint();
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method …
BestJewSinceJC 700 Posting Maven

Probably because whatever method repaint() indirectly calls (paint or update, I don't remember which) must be clearing your background. Get rid of the call to repaint() and instead try calling revalidate(). If that doesn't work and you post the rest of your code, I'll play around with it later tonight and try to help you out.

BestJewSinceJC 700 Posting Maven

If I put just one system.exit() at the end of the program, will this terminate each one as it is completed?

You don't need to put System.exit() in your program at all. Just take it out completely. Your program runs in a top to bottom (sequential) fashion, so it will step through your main() method step by step. When it sees a method call to getMeters() it will enter that method, go through the steps of that method, then return to where it left off in the main() method. . Once the end of the main() method is reached, your program will end automatically.

BestJewSinceJC 700 Posting Maven

Yeah. fileChooser.getSelectedFile() will return a File Object. Then you can use the basic I/O methods provided in the Java libraries to open, read, then write that file to whatever location you want.

BestJewSinceJC 700 Posting Maven

Place it in a JScrollPane to begin with. You should always have it in the Scroll Pane and set the Scroll Pane up so that it sizes how you want to. Don't keep putting it in and taking it out. See how to size a scroll pane

BestJewSinceJC 700 Posting Maven

And if fixing something causes more errors, you are doing yourself good. By putting the error back in your program on purpose, you might get rid of the other error messages, but you are actually further from solving your problem. Error messages are good, and many times, it will say 41 errors, you'll fix 1-3 things, and you'll have no errors anymore.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/java/generics/erasure.html

There is no way around it. If you want to "load specific classes" as you're saying, then you are going to have to explicitly name an interface, class, or abstract class in order to do so. But I'm pretty sure you probably don't need to do what you are trying to do, there is probably an easier way. To accomplish "loading something at runtime that is used by your game engine" you could just create a new Object of the specified class type. I'm not trying to frustrate you but I find it likely that you are heading down the wrong path. Maybe I'm wrong, if you think so feel free to ignore me.

BestJewSinceJC 700 Posting Maven

^Haha. You can easily look up the correct way to define a main method on google. Keep in mind that main is the method that runs when you start your program. Read about methods here.

http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html

BestJewSinceJC 700 Posting Maven

So a tool bar (you know, the link you would've seen if you'd looked through the last link I sent you)? Sorry if that isn't what you wanted, your post actually still makes no sense, typing in caps doesn't really help though.

http://java.sun.com/docs/books/tutorial/uiswing/components/toolbar.html

Majestics commented: Great Help... +0
BestJewSinceJC 700 Posting Maven

If you want to screw about with crap like 'OuterClassDemo.this.displayText' I'm glad you don't work for me, I assume your code is unreadable you arrogant little fish.

The Java tutorials make extensive use of anonymous inner classes and there are numerous articles online explaining their advantages. I assume the reason you don't use them is because you don't understand the syntax, but that doesn't mean that someone who does use them has "unreadable" code - quite the opposite actually.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html

JMenuBar, then you add JMenuItems to it if I remember correctly. In any case all the info you need is there.

BestJewSinceJC 700 Posting Maven

It's respectable that you posted a code snippet, despite the many reasons one could find not to do so. So respect to you for that. And I typically just up vote or leave a reputation comment (which auto up votes) if I see down votes that appear to be for no reason.

BestJewSinceJC 700 Posting Maven

It is hard to help you when you don't use code tags. You can either call the other class's main method using OtherClass.main(args go here) or you can figure out how to use Runtime.getRuntime.exec(). Those are the only two methods I know of but in my ~4 years of Java programming I haven't run into any situations where it is actually necessary to run one Java program from another. I also read your explanation a couple of times but I don't see why wanting input from a text file warrants running one java program from another. You needn't force text file input to be "rerouted" through the console (if that is what you are trying to do), simply have your program read from the text file instead.

BestJewSinceJC 700 Posting Maven

Your code only works if args.length >= 2 and if the args can be parsed as integers. In short, it is almost useless. As is upping a thread that is 3 years old.

BestJewSinceJC 700 Posting Maven
SavingsAccount sAccount[i]=new SavingsAccount();

Should be

sAccount[i]=new SavingsAccount();

As for the other errors I don't know because you didn't mention the line numbers. You should just paste the entire error message here.

BestJewSinceJC 700 Posting Maven

The scroll pane should only work if there is enough text in the JTextArea to make scrolling necessary. And I don't know about the Webcam, I've never worked with those in Java before. Read the API.

BestJewSinceJC 700 Posting Maven

The reason your code didn't work is because in your section of code where you were setting the JTextArea to say "initialized", you were also calling setVisible(false) which made the entire JFrame disappear. Hence you could not see the JTextArea anymore.

import javax.swing.*;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Random;
import java.util.*;
import java.text.*;

 
 class Home extends JFrame implements ActionListener, Runnable
 {
	JButton btndetect,btntest,btnstart,btnexit,btntransfer;
	ImageIcon ic,ic1,bc;
        JLabel lbltitle;
        JTextArea textArea ;

        JScrollPane scrollPane;
        JPanel panel;
        Thread t;
	
 public Home()
 {
 	setSize(800,570);
	setTitle(" CAMERA SETUP ");

/*ic1=new ImageIcon("ready3.jpg");*/
	
        textArea = new JTextArea(5,10);
        textArea.setPreferredSize(new Dimension(100, 100));
        scrollPane = new JScrollPane(textArea);
        textArea.setEditable(false);

        panel = new JPanel();
     
	lbltitle= new JLabel(ic1);	

	btndetect=new JButton(" Detect web cam ",ic);
	btntest=new JButton(" Test cam ");
	btnstart=new JButton("Start Survellance");
        btntransfer=new JButton("File Transfer");
        btnexit=new JButton("Exit");


	Container cp=getContentPane();
	cp.setLayout(null); 
        Insets ins=getInsets();

	textArea.setBounds(400,100,200,400);
	btntest.setBounds(40,200,150,50);
        btntransfer.setBounds(230,200,150,50);
	btnstart.setBounds(40,300,150,50);
        btndetect.setBounds(230,300,150,50);
        btnexit.setBounds(120,400,170,50);

	lbltitle.setBounds(0,0,850,570);
	
	
	btndetect.addActionListener(this);
	btntest.addActionListener(this);
        btntransfer.addActionListener(this);
	btnstart.addActionListener(this);
	btnexit.addActionListener(this);
        
        cp.add(panel, "north");
        cp.add(scrollPane);
        cp.add(textArea);
	cp.add(btndetect);
	cp.add(btntest);
        cp.add(btntransfer);
	cp.add(btnstart);
	cp.add(btnexit);
        cp.add(lbltitle);		

	cp.setBackground(Color.black);
     
	
  }



public void run()
{

  try
      {
               		 
          while(t.isAlive())
           {		
	Thread.sleep(1000);
	
	File f = new File("check/test.jpg");
	 if(f.exists())                  
	{
                    

	   String fname = f.getAbsolutePath();

                   FileInputStream instream = new FileInputStream(fname);

	int insize = instream.available();

	byte inBuf[] = new byte[insize];

                 int bytesread = instream.read(inBuf,0,insize);
	instream.close();
		                     	
		
 
                  }                    

            }
       }
         catch(Exception e)
         {
             System.out.println(e);
        }


}

public void actionPerformed(ActionEvent ae)
  {
				
	if(ae.getSource() == btndetect)  //action for button detect webcam
	{
		System.out.println("set to initialized");
		textArea.setText("initialized");
        //detect sc=new detect();
		//sc.show();
		//setVisible(false);
	}
 	
	
else 
         if(ae.getSource() == btntest)    //action for button "test webcam"
	{

	    try
                 {
           // JWebCam myWebCam = new JWebCam …
BestJewSinceJC 700 Posting Maven

Another question: what is the reason that you are using Runnable and implementing Runnable?

And instead of calling show(), you should be calling setVisible(true) on the JFrame. The show() method is deprecated, i.e. not used anymore.

BestJewSinceJC 700 Posting Maven

Object.getClass().getName();

Obviously that won't work on primitive types. But why do you want to do this to begin with?

BestJewSinceJC 700 Posting Maven

Can you show me what code you have so far? For example, were you already using Swing or were you using something else to display the image?

BestJewSinceJC 700 Posting Maven

Read this, it was originally posted on Daniweb by WaltP in this thread.

BestJewSinceJC 700 Posting Maven

In your switch statement you put the numbers in "". They can't go in quotes. You also capitalized the word Switch. It should be in lowercase. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html

Also, again, you did not use code tags. Read the rules stickied at the top of the forum.

BestJewSinceJC 700 Posting Maven

CODE TAGS. Use them. Read the rules.

BestJewSinceJC 700 Posting Maven

It is called an if statement, not an if loop. Only structures which repeat are called loops, such as for loops, do while loops, and while loops. If you can't use a return; or a break; statement, you could simply have a boolean variable (actually an int in C) and set it to "1". Before entering any loops or doing anything substantial, check to see if it is "1", and if so, don't do anything. This will have the effect of returning from the function.

BestJewSinceJC 700 Posting Maven

Kvass is right, but that isn't all you need to know to be able to do your program. Since the user is entering two words separated by a space, you will need to be able to get those two words into two separate Strings before you can follow Kvass's advice. The easiest way to do this would probably be to use a Scanner to read the text into two separate String variables.

Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your words");
String first = keyboard.next();
String second = keyboard.next();

The code I gave you above should work for correct input, but given bad input, it will fail. If you read the tutorial I linked you to, you will figure out how to prevent your program from crashing if the user enters bad input. You can also check out the Scanner API to look at available methods of the Scanner class.

BestJewSinceJC 700 Posting Maven
String f = firstLabel.getText();
float fi = Float.parseFloat(f);

That is the source of your first error. You are trying to parse "Fahrenheit: " as a float. It is a String. And we don't get rewards for helping people here. Besides which, giving away free copies of BioShock is undoubtedly illegal, so I wouldn't be surprised if one of the moderators here edits that out of your post and gives you an infraction.

BestJewSinceJC 700 Posting Maven

After you read in "val" in your for loop. kvass already gave you the code.

BestJewSinceJC 700 Posting Maven

1: delete element of that array[x]
2: create a new array with same size or newArray = new long [array.length*2]
3: copy array up til an empty element, stop, then arrayCopy(parameter) again from the next element with value
4. you can even set a condition statement to determine when to stop at what index when copying, but doing it this way, if you had to delete more than 1 customer, or more than 1 element, you wouldn't have to loop so many time

Your approach is wasteful and just bad programming. It wastes memory by creating another array, which is unnecessary. And it takes longer than my method takes because you have to copy all of the array's elements (other than the one that was deleted). My approach only copies the elements after the empty index. This means that your algorithm is always O(n) whereas mine is faster the closer the removed element is to the end of the array. Furthermore, you should only increase the size of the array in certain circumstances, such as when the number of elements in your array has surpassed 80% of the array's capacity. I've never heard of increasing the capacity of an array when an element is removed.

BestJewSinceJC 700 Posting Maven

I'm not really sure what that means, as the previous poster suggested, perhaps you should elaborate. JOptionPane ?

BestJewSinceJC 700 Posting Maven
BestJewSinceJC 700 Posting Maven

So are you having trouble displaying the Image, or are you having trouble figuring out which image to display?

To display the image, you'll need to show it in a JPanel or JFrame using Java Swing. To figure out which image to display, you can either have 5 Image Objects, then use a bunch of if statements, or you can use an array like peter suggested. An array is the better solution but if you don't want to learn arrays yet, then you can do something like this:

ImageIcon cardOne;
ImageIcon cardTwo;
ImageIcon cardThree;
ImageIcon cardFour;
ImageIcon cardFive;


public static void main(String[] args){
Random rand = new Random(5);
if (rand == 0) //display cardOne
if (rand == 1) //display cardTwo

..
}

Of course the above is just an example to demonstrate what I'm talking about - that code is not exactly what you need, and I did not create the ImageIcons properly. If you want to show an Image in Java Swing, you should use the ImageIcon tutorial. You can't just get an image to display on the console, so if you were expecting the image to show up next to your text output, then it isn't going to happen. But you can use Java Swing to display Images, text boxes, labels, etc. So one possibility would be to use an ImageIcon which allows you to put a picture up along with text for that picture.

BestJewSinceJC 700 Posting Maven

Focus Listener Tutorial

And changing the background color is just a question of looking up the methods in the JTextField API.

BestJewSinceJC 700 Posting Maven

You made the same mistake with almost all of your other Objects as well (such as JPanel, JScrollPane, etc). Why don't you fix those mistakes, then repost your code and I will take a look at it. And don't use chat speak or whatever you are using, it is almost impossible to figure out what you're saying. Use English.

BestJewSinceJC 700 Posting Maven

When peter says 'run random...' he means to generate a random number that is between 0 and the length of your array - 1. The reason for this is because if an array can store 5 numbers, then array[0], array[1], array[2], array[3], and array[4] are the storage spots. Hence the array uses storage spots 0-(length of the array minus 1). Read this to learn how to generate random numbers.

BestJewSinceJC 700 Posting Maven

We don't get anything for helping you, so when you ask questions that waste our time, you usually get mean or sarcastic responses. If you get a response at all.

See http://lmgtfy.com/?q=draw+a+diamond+java

BestJewSinceJC 700 Posting Maven

It isn't working because on line 33 you have

JTextArea textArea = new JTextArea( 5, 10);

but you should have

textArea = new JTextArea(5,10);

. If you leave it as the way you have it, then you are creating a completely different JTextArea than the one you are referring to in your actionPerformed method.

BestJewSinceJC 700 Posting Maven

Use code tags. The button is right there on your reply box. It says 'code'. That way we will know what line you are talking about.

BestJewSinceJC 700 Posting Maven

You fix it by not using a switch statement with doubles. It just conceptually does not make sense. You can use if statements instead of a switch statement; if statements will work with doubles. For example,

double value = 1.1;
if (value >= 0.0 && value <= 2.0) doSomething();
BestJewSinceJC 700 Posting Maven

jwenting is correct and you can find the same explanation on java.sun.com . . JDK is an SDK. They probably just call it JDK instead for the same reason that so many other things in Java have that J.

BestJewSinceJC 700 Posting Maven

You can't use doubles with switch statements. You can only use ints or chars. So it is saying possible loss of precision probably because it is automatically downcasting the double to an int.

BestJewSinceJC 700 Posting Maven

You're misunderstanding the concept of a for each loop. Change the code to this:

final int[] message = {60, 80, 100...}
		for(int i: message)
		{
			System.out.print((char)i);
		}
BestJewSinceJC 700 Posting Maven

The methods I described to you are only for updating UI elements. Not for executing long running tasks. Executing long running tasks on the UI thread (i.e. by calling asynchExec on your code block) is going to freeze up the UI, making it unresponsive to the user.

BestJewSinceJC 700 Posting Maven

It is called deleting an element from an array, not deleting the array. Just a little terminology thing - you sounded like you were saying you wanted to delete the entire array. Anyway, you can do this by moving each element back one like you suggested. So you'd need to use a for loop to do that. And you also need to keep track of what index the last element of the array is stored at (since your array probably won't be full, and definitely won't be full after you delete an element)

BestJewSinceJC 700 Posting Maven

Yeah, there are plenty of other forums, why don't you go get help there?

BestJewSinceJC 700 Posting Maven

Your directions seem insufficient. Did you not include all of the project directions?