I
ioannis
Gast
Hallo,
Ich habe folgenden Code und mir ist nicht ganz klar warum die JTextarea keinen Ausdruck "Das darf doch nicht wahr sein ausgibt!" Es geschiet nämlich garnichts. Das Frame wird komplet mit Grauer Farbe geladen, aber keine Text Area. Wenn ich das textInput =new JTextArea() auskommentiere dann läuft der weitere Teil des PRogramms wie gewünscht ab, ohne natürlich die JTextArea anzuzeigen..:-( Kann mir jemand weiterhelfen?
Vielen Dank
Ioannis
Ich habe folgenden Code und mir ist nicht ganz klar warum die JTextarea keinen Ausdruck "Das darf doch nicht wahr sein ausgibt!" Es geschiet nämlich garnichts. Das Frame wird komplet mit Grauer Farbe geladen, aber keine Text Area. Wenn ich das textInput =new JTextArea() auskommentiere dann läuft der weitere Teil des PRogramms wie gewünscht ab, ohne natürlich die JTextArea anzuzeigen..:-( Kann mir jemand weiterhelfen?
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new TextCounterApplet().init();
}
}
public class TextCounterApplet extends JFrame
implements ActionListener {
JTextArea textInput; // For the user's input text.
JLabel lineCountLabel; // For displaying the number of lines.
JLabel wordCountLabel; // For displaying the number of words.
JLabel charCountLabel; // For displaying the number of chars.
public void init() {
JFrame f = new JFrame("United Colors");
f.setVisible(true);
f.setSize(500,500);
f.setBackground(Color.RED);
f.getContentPane().setBackground(Color.darkGray);
textInput = new JTextArea("Das darf doch nicht war sein");
// Setze die Schriftart
Font schrift = new Font("SansSerif",Font.BOLD+Font.ITALIC,16);
textInput.setFont(schrift);
//textInput.setBackground(Color.white);
/* Create the text input area and make sure it has a
white background. */
/* Create a panel to hold the button and three display
labels. These will be laid out in a GridLayout with
4 rows and 1 column. */
JPanel south = new JPanel();
south.setBackground(Color.darkGray);
south.setLayout( new GridLayout(4,1,2,2) );
/* Create the button, set the applet to listen for
clicks on the button, and add it to the panel. */
JButton countButton = new JButton("Process the Text");
countButton.addActionListener(this);
south.add(countButton);
/* Create each of the labels, set their colors, and
add them to the panel. */
lineCountLabel = new JLabel(" Number of lines:");
lineCountLabel.setBackground(Color.white);
lineCountLabel.setForeground(Color.blue);
lineCountLabel.setOpaque(true);
south.add(lineCountLabel);
wordCountLabel = new JLabel(" Number of words:");
wordCountLabel.setBackground(Color.white);
wordCountLabel.setForeground(Color.blue);
wordCountLabel.setOpaque(true);
south.add(wordCountLabel);
charCountLabel = new JLabel(" Number of chars:");
charCountLabel.setBackground(Color.white);
charCountLabel.setForeground(Color.blue);
charCountLabel.setOpaque(true);
south.add(charCountLabel);
/* Use a BorderLayout on the applet. Although a BorderLayout
is the default, I want one with a vertical gap of two
pixels, to let the dark gray background color show through. */
//getContentPane().setLayout( new BorderLayout(2,2) );
/* The text area is put into a JScrollPane to provide
scroll bars for the TextArea, and the scroll pane is put in
the Center position. The panel that holds the button and
labels is in the South position. Note that the text area
will be sized to fill the space that is left after the
panel is assigned its preferred height. */
textInput.setLineWrap(true);
textInput.setWrapStyleWord(true);
JScrollPane scroller = new JScrollPane(textInput);
getContentPane().add(scroller, BorderLayout.CENTER);
f.getContentPane().add(south, BorderLayout.SOUTH);
} // end init();
public Insets getInsets() {
// Leave a 2-pixel border around the edges of the applet.
return new Insets(2,2,2,2);
}
...
...
...
...
Vielen Dank
Ioannis