The forums are currently locked and only available for read only access
ophe
Almost a full-blooded keyboard-warrior
Medlem
Forum Posts: 173
Member Since:
July 30, 2003
July 30, 2003
Offline
Här är ett början på en chatclient jag håller på att programmera. Hur gör jag för att den stora textrutan (window) ska bli scrollbar?
import java.io.*;
import java.lang.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Server1 extends JFrame implements ActionListener{
JTextField name = new JTextField(20);
JTextField input = new JTextField(50);
JLabel greeting = new JLabel("Enter your nickname");
JTextArea window = new JTextArea(10,50);
public Server1() { //Kontruktor
Container content=getContentPane();
content.setLayout(new BorderLayout());
JPanel content2 = new JPanel();
content2.setLayout(new FlowLayout());
content2.add(greeting);
content2.add(name);
content.add(content2, "North");
content.add(window,"Center");
content.add(input, "South");
greeting.setHorizontalAlignment(JLabel.CENTER);
name.addActionListener(this);
input.addActionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
window.setEditable(false);
window.setVisible(false);
input.setVisible(false);
name.requestFocus();
pack();
setVisible(true);
}
public static void main(String[] args){
Server1 h= new Server1();
}
//lyssnarmetod
public void actionPerformed(ActionEvent e){
if (e.getSource().equals(name)){
if (name.getText().length()>0){
String namn = name.getText();
greeting.setText("Nickname: " + namn);
name.setVisible(false);
window.setVisible(true);
input.setVisible(true);
input.requestFocus();
pack();
window.append("Welcome " + namn + "!" + "n");
}
} else if (e.getSource().equals(input)){
if (input.getText().length()>0){
window.append(name.getText()+ "> "+ input.getText() + "n");
input.setText("");
}
}
}
}
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1030
Currently Online:
Guest(s) 161
Currently Browsing this Page:
1 Guest(s)
1 Guest(s)
Top Posters:
Andreas Galistel: 16287
Jonas Klar: 15897
ilg@dd: 10810
Nyhet: 10607
Mind: 10550
Ctrl: 10355
Gueno: 9881
Guest: 9344
Snorch: 8881
Callister: 8468
Newest Members:
PetrbonFU PetrbonFU
Karine Bembry
Dolores Mcdaniels
Anibal McLeish
Francisca Alt
Alfie Everhart
Lester Huitt
Orlando Jorgensen
Mikki Lundgren
Dakota Kozlowski
Forum Stats:
Groups: 11
Forums: 59
Topics: 146630
Posts: 1300967
Member Stats:
Guest Posters: 2
Members: 79425
Moderators: 0
Admins: 11
Administrators: nordicadmin, Henrik Berntsson, Anton Karmehed, Carl Holmberg, Joel Oscarsson, Mikael Linnér, Mikael Schwartz, Andreas Paulsson, Nickebjrk, Mattias Pettersson, EmxL
© Simple:Press —