vex 0 Newbie Poster

Every file is binary data by definition.
A text file contains only data in the specific code page/character set you're using. Which that is would depend on your locale.

You'd have to attempt to read the file and throw an exception if you encounter data that doesn't map to text in your expected codepage.

I guess I will just check the extension. Sounds much easier. I will only be dealing with txt and dat files.

Thanks for the input though.

vex 0 Newbie Poster

Thanks for the reply

I am also using JFileChooser to save files. When the dialog opens I can type the filename I want to save as. If I do not type a extension it will not add one. Is there an option for setting a default extension. ie, If I save a Word document there is no need to type the .doc

Thanks again

vex 0 Newbie Poster

Is there a simple way to test wether or not a file is binary or text???

Thanks in advance

vex 0 Newbie Poster

I have edited out my original question. I guess I needed to see the questions asked to figure it out :o

vex 0 Newbie Poster

When using a JDialog how can I tell it where to open on the screen? Let's say I want to open it in the middle.

Can I add a JDialog to a pane in a JFrame?


A link to the proper java doc would be great.


Thanks in advance

vex 0 Newbie Poster

sure did everything works fine till I add the JList I can comment out the JList and use a JLabel and it works fine

vex 0 Newbie Poster

Is there something about adding a JList to GridBagLayout that I am missing. I want to place a JList between a JLabel and a JTextArea. No matter what I do the list seems to stay in column 1.

I am only using GridBagLayout in the west pane(wP) I have tried messing with the weights and I am stumped. I must be missing something!!!

I just want everything in column 0


First code block is the layout. Second is the entire project so far.

Project6()
	{
		super("James W Project6");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		nP = new JPanel();
		nP.setLayout(new FlowLayout());
		nP.setBackground(new Color(85,107,47));
		npLbl = new JLabel("South Park Photo Album");
		npLbl.setFont(fifty);
		nP.add(npLbl);
		add(nP, BorderLayout.NORTH);

		sP = new JPanel();
		sP.setLayout(new GridLayout(1,2));
		sP.setBackground(new Color(85,107,47));
		spLbl = new JLabel("Select Font Size");
		spLbl.setFont(thirty);
		spLbl.setHorizontalTextPosition(SwingConstants.LEFT);
		sP.add(spLbl);
		jsl.setMajorTickSpacing(2);
		jsl.setPaintTicks(true);
		jsl.setPaintLabels(true);
		jsl.addChangeListener(this);
		sP.add(jsl);
		add(sP, BorderLayout.SOUTH);

// Problem is in here

		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.BOTH;
		wP = new JPanel();
		wP.setLayout(gridbag);
		wP.setBackground(new Color(189,183,107));

		wpLbl = new JLabel("Sayings");
		wpLbl.setFont(twenty);
		constraints.ipady = 50;
		constraints.weighty = 0.3;
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.anchor = GridBagConstraints.FIRST_LINE_START;
		gridbag.setConstraints(wpLbl, constraints);
		wP.add(wpLbl);

		sayList = new JList(sayings);
		sayList.setVisibleRowCount(3);	
		sayList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		constraints.weightx = 0.0;
		constraints.weighty = 0.0;
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.anchor = GridBagConstraints.LINE_START;
		gridbag.setConstraints(sayList, constraints);
		wP.add(new JScrollPane(sayList));
		sayList.addListSelectionListener(this);


		cart =  new JTextArea(11,12);
		cart.setBackground(new Color(189,183,107));
		cart.setBorder(BorderFactory.createTitledBorder
						(BorderFactory.createLineBorder(Color.black),"Cart:"));
		cart.setEditable(false);
		cart.setLineWrap(true);
		constraints.gridx = 0;
		constraints.gridy = 2;
		//constraints.anchor = GridBagConstraints.PAGE_END;
		gridbag.setConstraints(cart, constraints);
		wP.add(cart);
		add(wP, BorderLayout.WEST);






		eP = new JPanel();
		eP.setLayout(new GridLayout(12,1));
		eP.setBackground(new Color(189,183,107));
		lbl1 = new JLabel("Available");
		lbl1.setFont(twenty);
		lbl2 …
vex 0 Newbie Poster

My next qusetion would be WHY?


--------------------Configuration: Ch13_4 - j2sdk1.4.2_08 <Default> - <Default>--------------------
E:\CIS1500\Junk\Ch13\Ch13_4\src\Ch13_4.java:14: ']' expected
deck[0] = new Deck();
^

E:\CIS1500\Junk\Ch13\Ch13_4\src\Ch13_4.java:14: <identifier> expected
deck[0] = new Deck();
^

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Ch13_4 extends Applet implements ActionListener 
{
	
//	private Button deal, twist, stick;
//	private TextField plyr, comp;
//	private Label lblPlyr, lblComp;
//	private int pScore, cScore, button;

	Deck[] deck = new Deck[3];
	deck[0] = new Deck();  //this is line 14
	
	
	public void init() 
	{
//		deal = new Button("Play Again");
//		add(deal);
//		deal.addActionListener(this);
//		twist = new Button("Twist");
//		add(twist);
//		twist.addActionListener(this);
//		stick = new Button("Stick");
//		add(stick);
//		stick.addActionListener(this);
//		lblPlyr = new Label("Player score:");
//		add(lblPlyr);
//		plyr = new TextField(10);


//		add(plyr);
//		lblComp = new Label("CPU score");
//		add(lblComp);
//		comp = new TextField(10);
//		add(comp);
		
		
		
	}
	public void actionPerformed(ActionEvent event)
	{
	
	}

	
	
	
	
	
	public void paint(Graphics g) 
	{
		
		//g.drawString("" + deck[1].suit, 50,50);
		
	}
	
	
	


}
vex 0 Newbie Poster

Ok

I would like to use Deck in a third class.

Deck myDeck = new Deck();


Then in paint I try

g.drawString("" + myDeck[1].suit, 50,50);

It says 'array required, but Deck found'


If I try

Deck[] myDeck = new Deck();


I get 'incompatable types'

I hate asking for help BUT I need the correct way to use(instantiate) a Deck object.

Thanks in advance

public class Card
{
public int rank;
public String suit;
}


public class Deck
	{
		private int random = 0;
		private Card[] deck = new Card[52];
		final String[] suit = {"hearts", "diamonds", "spades", "clubs"};
		
		public Deck()
		{
			int cardNumber = 0;
			for(int suitNo = 0; suitNo < 4; suitNo++)
			{
				for(int rank = 1;rank < 14; rank++)
				{
					deck[cardNumber] = new Card();
					deck[cardNumber].suit = suit[suitNo];
					deck[cardNumber].rank = rank;
					cardNumber++;
				}
			}
		}
		
		
	}
vex 0 Newbie Poster

is there a command to bring up the last command typed?

vex 0 Newbie Poster

What temp. is the CPU reaching? You should be able to see the temp from the BIOS.

vex 0 Newbie Poster

Just install win98 and change the default install directory.

vex 0 Newbie Poster

So for the above homework question, the following should be fine?

import java.awt.*;
import java.applet.*;

public class Ch8_10 extends Applet
{
	private float d = 2.0f, sum = 1.0f, term = 0.0f;	
	  
	public void paint(Graphics g)
	{
	
		do	
		{
			term = 1/d;
			sum = sum - term;		
			d++;
			sum = -(sum);		
		
		}
		while(term > 0.0001);		
		
		
		g.drawString("Sum = "+ sum,20,20);
		g.drawString("Term = " + term, 20, 40);
		g.drawString("Denominator = " + d, 20, 60);
	}
}

Output:

Sum = -0.6930917
Term = 1.0E-4
Denominator = 10001.0


Are there better ways to do this? I wanted to make it work before I asked.

Thanks for the help

Jay

vex 0 Newbie Poster

Is there a simple way to change a positive number to a negative number???

float d = 1.0f; How can I flip d between pos. and neg.?

Thanks in advance

vex 0 Newbie Poster

8.10 Sum of series Write a program to calculate and display the sum of the series:

1 - 1/2 + 1/3 - 1/4 + ...

Until a term is reached that is less than 0.0001


I do not need help with the code! What comes next in the series? Is there a formula for this?

It's been far too long since I took math!!!

Thanks in advance

vex 0 Newbie Poster

thanks. do you know of anywhere either in the uk mainland or online where i might be able to buy one.

also how do i ensure that the pc's and the router are set to DHCP, and how can i ensure it'll work with my ISP which is virgin.net

cheers:D

Ebay

Cheers

vex 0 Newbie Poster

wow... try this....

Random random = new Random(); 
boolean a = random.nextBoolean();

Worked great. I was looking in Math and not Random.

Thanks

vex 0 Newbie Poster

How can I generate a random boolean? Is there a method for this?

Thanks in advance

vex 0 Newbie Poster

What is the difference between grammar and syntax in a language?


Thanks in advance

vex 0 Newbie Poster

Could someone decribe the differences between HTML and XML.

Thanks in advance

vex 0 Newbie Poster

Could someone decribe the differences between HTML and XML.

Thanks in advance

vex 0 Newbie Poster

What development kit is the most widely used? Which is the easiest to use?

Thanks in advance