eLL Pascual

Greenhorn
+ Follow
since May 22, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by eLL Pascual

So it has to be really short?

Oh my God, I dont know how to make that short because I guess this is the shortest it can be. All the codes here are necessary to run the program and address my problem.

This program is a notepad...
The problem here is that I am trying to make the program capable of using undo but the problem is it cannot tell weather an action happened.
[ July 11, 2008: Message edited by: eLL Pascual ]
15 years ago
Im sorry for not explaining my problem very clearly...
In your nokia cellphone, there are corresponding letters in every number right?

That's how the number 23 got the letters ad ae af etc... the program will print all possible letter combinations.

These are the letters:
number 1: special characters
number 2: abc
number 3: def
number 4: ghi
number 5: jkl
number 6: mno
number 7: pqrs
number 8: tuv
number 9: wxyz
number 0: space

I haven't started yet because I dont know how.
Actually I already tried it. I used nesting for loop and if-else but the problem is my program is not printing anything correctly. So my problem is merely everything.
15 years ago
I really want to make a program that is accepting integer values and I want that program to print all possible letter combinations assigned to each number or maybe not all. Just like when you type 23, the program should print "ad ae af bd be bf cd ce cf".

How can I do that?

Please help me. Thanks.
15 years ago
Can I make a program which is randomly selecting an int value from an array?For example this is my array:

int []numArray = {12,45,36};

Can I make the class Random choose from that array? Or is there anything that can do that?

Thanks!
15 years ago
I am also having a problem with undo and redo... Please help me again...
I have here my program codes...
This is an SSCCE...

15 years ago
I am having a problem with my program...
I don't know what's wrong... Please help me...
I have here my program codes.

This is an SSCCE...

15 years ago
This is my code... but it is not yet a SSCCE...

code:
----------------------------------------------------------------------------

public class notepad
{

HashMap<Object, Action> actions;

protected UndoAction undoAction;
protected RedoAction redoAction;
protected UndoManager undo = new UndoManager();

public constructor(){
actions = createActionTable(textArea);
}

class UndoAction extends AbstractAction {
public UndoAction() {
super("Undo");
setEnabled(true);
}

public void actionPerformed(ActionEvent e) {
try {
undo.undo();
}
catch (CannotUndoException ex) {
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}
updateUndoState();
redoAction.updateRedoState();
}

protected void updateUndoState() {
if (undo.canUndo()) {
setEnabled(true);
putValue(Action.NAME, undo.getUndoPresentationName());
} else {
setEnabled(false);
putValue(Action.NAME, "Undo");
}
}
}

protected class MyUndoableEditListener implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent e) {

undo.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
}
}

private HashMap<Object, Action> createActionTable(JTextComponent textComponent) {
HashMap<Object, Action> actions = new HashMap<Object, Action>();
Action[] actionsArray = textComponent.getActions();
for (int i = 0; i < actionsArray.length; i++) {
Action a = actionsArray[i];
actions.put(a.getValue(Action.NAME), a);
}
return actions;
}

private Action getActionByName(String name) {
return actions.get(name);
}

}
----------------------------------------------------------------------------
[ June 11, 2008: Message edited by: eLL Pascual ]
15 years ago
Can you pls help me do undo...

I already have a complete and working code of undo and undoAction but the problem is it is so confusing and I can't understand the importance of each code. Maybe you can give me the steps on how to do it and I will just compare it to the codes I have...

Please help me...

Thanks!
15 years ago
What seems to be the problem when you see this error message?

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: parent not showing on screen

The error appears when I place the 'textArea.addActionListener(this);' right after 'textArea = new JTextArea(5,10);'

Just like this:

code:
----------------------------------------------------------------------------

textArea = new JTextArea(5,10);
textArea.addMouseListener(this);

----------------------------------------------------------------------------

when they are like this there is no error and no right click.

code:
----------------------------------------------------------------------------

textArea.addMouseListener(this);
textArea = new JTextArea(5,10);

----------------------------------------------------------------------------

I want my textArea to have a right click but it is not working.

Is there anything missing here?

code:
----------------------------------------------------------------------------

public void mousePressed(MouseEvent me)
{
System.out.print("Mouse Right-Clicked!");//Test if the mousePressed is working
if(me.getModifiers() != 0){
popup.show(this, me.getX(), me.getY());

}
}

public void mouseClicked(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}

----------------------------------------------------------------------------



To give you an overview of my code, this is it. My textArea is inside:

code:
----------------------------------------------------------------------------

public Container createContentPane(){

...
textArea = new JTextArea(5,10);
textArea.addMouseListener(this);
...
return contentPane;

}

----------------------------------------------------------------------------

which is called inside:


code:
----------------------------------------------------------------------------

public static void createShowGUI(){

...
notepad notpad = new notepad();//class instance
frame.setContentPane(notpad.createContentPane());

}

----------------------------------------------------------------------------

I already tried to put the 'textArea.addMouseListener(this);' inside the constructor but it is not
working.

Please help me. Thanks!
15 years ago
In my program, I created a menu bar and a toolbar, meaning, aside from the menu bar I have buttons as a (standard)toolbar also. But the problem is when I click the menu items, the program is calling the message box that is supposedly a message box that should appear when I click a button from the toolbar, and when I click a button from the toolbar, it is throwing

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to javax.swing.JMenuItem

Why is it happening?

Actually this my code in actionPerformed:

code:
----------------------------------------------------------------------------

public void actionPerformed(ActionEvent ae){

JMenuItem source = (JMenuItem)(ae.getSource());

String cmd = ae.getActionCommand(); //for toolbar buttons
String description = null; //for toolbar button's JOptionPane


if(source.getText().equalsIgnoreCase("open") || OPEN.equals(cmd)){

description = "OPEN";

try{
FileInputStream fi=new FileInputStream(openfile());
BufferedReader br=new BufferedReader(new InputStreamReader(fi));
String s01=br.readLine();
if(s01 != null) textArea.setText(s01);
br.close();
fi.close();
}
catch(Exception ex){}
}
else if(source.getText().equalsIgnoreCase("save as")){
try{
FileOutputStream fo=new FileOutputStream(writefile());
PrintStream ps=new PrintStream(fo);
ps.println(textArea.getText());
ps.close();
fo.close();
}
catch(Exception ex){}
}


displayResult("The user clicked " + description);
}

----------------------------------------------------------------------------

If it is confusing and you need to see my other codes, please tell me.

Thanks!
15 years ago
Thank you Rob Prime.
- Add line breaks myself.
- Use .append

I didnt realize I am using setText().

Thanks.
15 years ago
Details? Ahhmmm. Actually I decided to stop using Scanner because I saw a demo using FileInputStream and FileOutputStream working very well. I just followed how the programmer used the codes and found myself dealing with the same problem I had when I was still using Scanner. FileInputStream is reading only one line of the text area, it is ignoring the succeeding lines. While the FileOutputStream in the demo is writing texts in a text file the way I typed the texts in the textArea. But in my own program, it is writing the texts in one straight line only even though I had several lines. Look at my example.

In my textArea:

Cedric
Diggory
Harry Potter

In the text file:

[] - supposedly a square

Cedric[]Diggory[]Harry Potter

But the demo is working well. I dont know what is the problem. Actually the only difference between my codes and the programmer's code are names.

Since Campbell told me that Scanner is very easy to use, I guess I will show you my code and tell me what is wrong. The problems with my Scanner is the same with the problems I mentioned above.

code:
----------------------------------------------------------------------------

else if(source.getText().equalsIgnoreCase("open")){
System.out.print("Open Press");
int returnVal = fileChooser.showOpenDialog(notepad.this);
File file = fileChooser.getSelectedFile();

Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader(file)));

while (s.hasNext()) {
textArea.append(s.next());
}
}
catch(Exception e){}
finally {
if (s != null) {
s.close();
}
}

}

----------------------------------------------------------------------------

I dont know how to use Formatter yet but I already downloaded a Formatter API so I guess I have to study it first.
15 years ago
About the title of my post...

Actually, I created open and save menu items so I thought "About menu items" is the best title for my post. But my question is how to make them work.
15 years ago
I thought I can move my post myself but this is what I got.

"Only administrators or moderators may perform this action."

Campbell Ritchie, please move my post to I/O forum.
15 years ago
What does it mean when you have this in your folder?

notepad$1.class
notepad.class

I used to ignore the first one but I saw a fully working jar file with all ten ...$10.class inside. So now I am wondering if it is necessary to include all of them in my jar file 'coz until now I haven't
made my works jarred and working. I have them jarred but working no.There is always an error. Thanks!
15 years ago