thank you!
Thank you, this worked perfectly!
If I change my mac address, wil that also change my ip address?
I have this code that is suppose to append text to a JTextPane, using the Document method insertString(). I can't seem to get the attribute argument right, so maybe one of you can point me in the right direction...
Here is the one line of code giving me problems, just at the attribute argument
doc.insertString(lastPosition,s,(AttributeSet)null);
doc == myTextPane.getDocument
last pos == myTextPane.getSelectionEnd()
and s == the string to be inserted
It's just the atrributes part I can't seem to get working..
Any ideas?
I just read that you can't do this in a JTextArea. Im gonna have to convert to JTextPane.
I know how to se the font of a regular JTextArea, but how would I get an reference to the selected text and only select that?
Here is what I have so far:
setFont(new Font(font, style = Font.BOLD, size));
this works but changes whole area
textArea2.getSelectedText().setFont(new Font("sansserif",Font.BOLD, 12));
this doesn't work, and this is what I need..
How can i do this/
Thanks for correcting that, I'm getting ready to test it.
Thanks man, that helped a bunch.
I see what you mean, but actually the code I posted covers that. I tried this:
One
Two
Three
Four
On seperate lines withough any space, and it showed up as four words. I thought it would have the effect you were suggesting.
So do you personally think this would be ok, or would you make it more specific in what it defines as a word?
What do you mean detect line breaks and tabs? Is this necesary.
I have a method that counts the number of words in a JTextArea. It works pretty good, except for the fact it counts characters that's not letters as words(such as "!@#$" would be a word)...
Here is the code that I have got so far(no erros, compiles and runs fine, just needs to be more specific in what it searches for)
public void processWordCount()
{
String data = textArea2.getText();
Scanner s = new Scanner(data);
Pattern p = Pattern.compile(" ");
String words = null;
int count = 0;
while (s.hasNext())
{
words = s.next();
count += 1;
}
JOptionPane.showMessageDialog(null, "Word Count: " + count);
}
I need to get the position in a JTextArea...Anyone know how to do this?
I have a text editor I've been working on, and I'm having some trouble with the undo/redo functions... It doesn't work, and I don't know what's wrong with it. I posted all of my code dealing with the undo function. I know it's a lot, but maybe you wont mind helping me. Any suggestions will help.
UndoManager undoManager;
textArea2.getDocument().addUndoableEditListener(this);
textArea2.addFocusListener(this);
public void createUndoManager()
{
undoManager = new UndoManager();
}
public void removeUndoManager()
{
undoManager.end();
}
public void focusGained(FocusEvent fe)
{
createUndoManager();
}
public void focusLost(FocusEvent fe)
{
removeUndoManager();
}
public void undoableEditHappened(UndoableEditEvent uee)
{
undoManager.addEdit(uee.getEdit());
}
public void undoableEditHappened(UndoableEditEvent uee)
{
undoManager.addEdit(uee.getEdit());
}
if ((ae.getSource() == btnUndo) || ae.getActionCommand().equals("Undo"))
{
try
{
undoManager.undo();
}
catch (CannotUndoException cue)
{
Toolkit.getDefaultToolkit().beep();
}
}
}
Thanks man. I guess I'll just keep it one class then, since it is pretty simple.
Does it print a test page ok? How good is your link? If you have a good wireless link, then there is nothing about the setup that should cause you problems. Try printing something really small. If that goes ok then I would suspect your wireless link is questionable if not then your printer setup.
It's probably my printer setup. One thing that was suspicious was when it asked what kind of wireless card I was using. It wasn't on there(linksys), so I selected the top option which was generic network card.
I made a text editor with very basic funtionalities. I wrote it all in one class because I really wasn't sure what to put into other classes. Right now the code is pretty messy and I want to rewrite it. I was wondering if anyone could give me some input on the different classes you would use if you were going write a text editor.
I tried this and got the printer to come up as one of the available printers, but when I tried printing, it took about five minutes and then it said there was an error printing.
Excuse if it needs to the respect Sir perefeccion, my intention is not to fight, and will forget this, I am here with a different intention this. Greetings perfect Mr.. Excuse it needs the respect.
haaa, and or callate, that bothers the people with that character, Perhaps you are created much so that or you have time aqui? I also conosco other forums, and also have many sent messages, if he is that what she makes you feel with the desire to walk educating everybody. your you are the one of the idiot and incoherent generation. either better I shut up myself, but callate or! not me jodas
Either you used a translation program to translate this into english, or your english just sucks wieners.
Anyway's spanish is a third world language: Why learn or use it?
I have the printer connected to a desktop computer and would like to be able to print wirelessly from my laptop. I don't know how to do this, and would certainly appreciate your help.
Is it possible to print wirelessly from a laptop with a linksys g card? I do have a router but not a print server, so i dont know if this is possible or not. If it is, could someone tell me how to do this?
Thanks jerbo, that worked perfectly!
and which line throws the exception?
in the: public static void main(String[] args)
I have set up everything correctly just getting this one error
I keep getting a null pointer exception with this code:
It's suppose to load a text file into a textArea.
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(this);
String getFile = chooser.getName();
if(returnVal == JFileChooser.APPROVE_OPTION)
{
try {
FileReader filegetter = new FileReader(getFile);
BufferedReader br = new BufferedReader(filegetter);
String line = br.readLine();
while ((line)!= null)
{
textArea2.setText(line);
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (Exception myE)
{
myE.printStackTrace();
}
}
Do you have a java enabled browser? And it might be helpful to post your code to make sure there is no errors in it.
The reinstalling I did with Gost. When I see HD it is not full because of Linux :lol:
I had created two hardrives independed.
It is right.I did partion whith magic partion.On one hardrive sit windows :evil: and on other sit Linux :lol: .And this cause it to boot directly into one OS(windows) and ignore the other(Linux).
.
When I used partition magic it damaged the bootloader of windows and I was never able to recover windows but it booted directly into linux. After that I never used partition magic again, and I strongly advise against it. Just using the partitioner in the linux setup is fairly easy, and that's what I have always used. I would just go through with the linux installer it's much easier for dual booting and it won't damage the other OS' bootloader. And don't worry about creating two diffrent HD's before installing, deal with that during the instalation.
It is a possibility that you formated over the Linux partition.
This is most likely what's happend unless maybe you used something like partition magic to partition. This can sometimes cause it to boot directly into one OS and ignore the other.
I think you could use something like this:
textField1.requestFocus();
When I'm in linux(mandrake 9) I cannot use the touchpad on my laptop but I can use the mouse. Anyone know how to make it to were I can configure it for my touchpad?
Usually lilo plays nicer than grub when you want to dual boot with xp.
>You have a better way?
As a matter of fact, I do:public String reverse ( String s ) { StringBuffer buffer = new StringBuffer ( s ); return buffer.reverse().toString(); }
Though that probably won't work for homework. The obvious way is to use a loop, but because Strings are immutable you need to either do something stupid, or perform conversions. One conversion is using an array:
public String reverse ( String s ) { int len = s.length(); char rev = new char[len]; for ( int i = 0; i < len; i++ ) rev[i] = s.charAt ( len - i - 1 ); return new String ( rev ); }
Both of these are considerably better than recursion, and I can think of at least half a dozen more variations on this theme.
I guess your right. This is a much better way. At first I was thinking that although rucursion might not be the best answer but sometimes clarity and ease is the overriding concerne. Although your method was actually more clearer and easier to understand than mine.
>This is how I would do it
You would use a recursive function for a problem clearly unsuited to a recursive solution? That's a shame.
You have a better way?
This is how I would do it:
public class ReverseString
{
public String reverse(String arg)
{
String tmp = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last char
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining chars
String remainingString = arg.substring(0, arg.length() -1);
tmp = lastChar + reverse(remainingString);
return tmp;
}
}
}
import java.io.*;
public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}
The finally clause executes wheter or not an exception is thrown. Except when a catch clause invokes System.exit() of course!
Do you know anything about jdbc?
I think it might be best if you post the code you have so far. I think I might understand what your saying but I'm not sure.
You had most of it right..Just a few lines needed to be left off.
import java.io.*;
import javax.swing.JOptionPane;
class MessageBoxInput
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData = JOptionPane.showInputDialog(null,
"enter a positive 4 digit number",
"homework3",
JOptionPane.QUESTION_MESSAGE);
int int1 = Integer.parseInt(inData.substring(0,1));
int int2 = Integer.parseInt(inData.substring(1,2));
int int3 = Integer.parseInt(inData.substring(2,3));
int int4 = Integer.parseInt(inData.substring(3,4));
JOptionPane.showMessageDialog(null,
int1+
"\n" + int2+
"\n" + int3+
"\n" + int4,
"homework3",
JOptionPane.QUESTION_MESSAGE);
}
}
I think the easiest way to do this is to use substring(). Like so...
import java.io.*;
class MessageBoxInput
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
System.out.println("Please input a 4 digit number");
inData = br.readLine();
int int1 = Integer.parseInt(inData.substring(0,1));
int int2 = Integer.parseInt(inData.substring(1,2));
int int3 = Integer.parseInt(inData.substring(2,3));
int int4 = Integer.parseInt(inData.substring(3,4));
System.out.println("-----------------------");
System.out.println("\n" + int1);
System.out.println("\n" + int2);
System.out.println("\n" + int3);
System.out.println("\n" + int4 + "\n");
System.out.println("-----------------------");
}
}
Your question is somewhat unclear. But maybe I got it right. I posted code what I thought you were wanting if it's not let me know...
import java.io.*;
class NumbersandInput
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
int i;
int i2;
System.out.println("Please enter an integer");
i = Integer.parseInt(br.readLine());
i2 = i;
System.out.println("\n Would you like to change the number?");
inData = br.readLine();
if (inData.equals("Yes"))
{
try {
System.out.println("\n What would you like to change it to?");
i2 = Integer.parseInt(br.readLine());
}
catch (NumberFormatException e) {}
}
else {
System.out.println("No change was made");
}
System.out.println(" \n \n \n The staring value of the integer was: " + i);
System.out.println(" The eding value of the integer was: " + i2);
}
}
If it were me I would use an if-elseif-else statement rather than switch-case.
import java.io.*;
public class ifelsechain2
{
public static void main(String[] args) throws IOException
{
String string1;
int num1;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Enter a Grade: ");
string1 = br.readLine();
num1 = Integer.parseInt(string1);
if (num1 >= 90 && num1 <=100)
{
System.out.println("You have an A! ");
}
else if (num1 >= 80 && num1 <= 89)
{
System.out.println("You have a B! ");
}
else if (num1 >= 70 && num1 <= 79)
{
System.out.println("You have a C. -_-");
}
else if (num1 >= 60 && num1 <= 69)
{
System.out.println("You have a D. ");
}
else if (num1 >= 0 && num1 <= 59)
{
System.out.println("You have a F. ");
}
else
{
System.out.println("You messed up");
}
}
}
Well what was the point in posting the same code twice when someone else already had?
tht's very easy
class Test{
public static void main(String args[]){
int[] arr = new int[20];
for(int j=0;j<20;j++){
arr[j]=j;
}
for(int i=0;i<arr.length;i++){System.out.println(arr);
}
}
}
arr is array containing 20 integers
this will print first 20 from 0 to 19
this will do the job
Of course it was easy for you. You basicly copied my code above.
Something like this?
class ArrayOfInts
{
public static void main(String[] args)
{
int[] myNums = new int[20];
for (int x=0; x<20; x++)
{
myNums[x] = x * 5;
}
for (int y=0; y<myNums.length; y++)
{
System.out.println("myNums[" + y + "] = " + myNums[y]);
}
}
}
I really like to play chess and thought about trying to actually make a chess game. Only im not sure were to even start. If anyone in here has ever done this can you give me some tips on how to get started and how difficult of a task this would be?
Have you even attempted to try?
You can also get it to print the letters individually if you put the println() statement in the first class.
Here is how to reverse an inputed string, just apply it all to Int and you should have your program:
class ReverseString
public class ReverseString
{
public String reverse(String arg)
{
String tmp = null;
if (arg.length() == 1)
{
return arg;
}
else
{
//extract the last char
String lastChar = arg.substring(arg.length()-1,arg.length());
//extract the remaining chars
String remainingString = arg.substring(0, arg.length() -1);
tmp = lastChar + reverse(remainingString);
return tmp;
}
}
}
class TestReverse
import java.io.*;
public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}
lazy bobo.
Thats a good one. I like that.
In the java forum there should be something at the top that says: java code snipets. just go there and find were it says to submit one.