GUI inquiry
Dear all,
I'm new to JAVA GUI and hope you could help on 2 questions.
1) No matter how I constrain textarea (e.g. set column, row), when it is fed
with a long string, the textarea just shows 2 rows and many columns. Is
there any trick to force the swapping of line? I've tried both textarea and
jtextarea.
2) I'm modifying the mouse listening codes written by somebody else before:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Listener implements ActionListener
{
private BioProject bioProject;
public Listener(BioProject bioProject)
{
this.bioProject = bioProject;
}
public void actionPerformed(ActionEvent e)
{
JButton jButton = (JButton) e.getSource();
if(jButton == bioProject.getFileButton())
{
FileDialog fileDialog = new FileDialog(bioProject.getJFrame(), "Select
the source file" , FileDialog.LOAD);
fileDialog.show();
if(fileDialog.getFile() != null)
bioProject.readFile( fileDialog.getDirectory() + fileDialog.getFile());
}
else if(jButton == bioProject.getPrevious10Button())
bioProject.previous10();
else if
.....
}
}
and then "duplicate" one for key listening, but it does not respond at all
( System.out.print("up") doesn't print anything ). I've already added
addlistener at the bioproject.java, say at jframe, contentpane, display
panel but none of them works. Is that listening unable to work on both mouse
and key events?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class KListener implements KeyListener {
private BioProject bioProject;
public KListener(BioProject bioProject)
{
// super();
this.bioProject = bioProject;
}
public void keyPressed(KeyEvent e) {
System.out.print("up");
int Key = e.getKeyCode();
if(Key == KeyEvent.VK_UP) {
System.out.print("up");
bioProject.up();
} else if(Key == KeyEvent.VK_DOWN) {
System.out.print("dn");
bioProject.down();
} else if(Key == KeyEvent.VK_PAGE_UP) {
System.out.print("pgup");
bioProject.previous();
} else if(Key == KeyEvent.VK_PAGE_DOWN) {
System.out.print("pgdn");
bioProject.next();
}
}
public void keyTyped(KeyEvent e) {
System.out.print("KEY TYPED: ");
}
/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e) {
System.out.print("KEY RELEASED: ");
}
}