import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.text.BadLocationException;
class game1216 extends JFrame{
JTextArea area;
JTextArea disparea;
public static void main(String args[]){
game1216 frame = new game1216("タイトル");
frame.setVisible(true);
}
game1216(String title){
setTitle(title);
setBounds(100, 100, 300, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
area = new JTextArea();
area.setLineWrap(true);
JScrollPane scrollpane1 = new JScrollPane(area);
scrollpane1.setPreferredSize(new Dimension(120, 120));
disparea = new JTextArea();
disparea.setLineWrap(true);
disparea.setEditable(false);
disparea.setBackground(Color.LIGHT_GRAY);
JScrollPane scrollpane2 = new JScrollPane(disparea);
scrollpane2.setPreferredSize(new Dimension(120, 120));
JButton button1 = new JButton("全て取得");
button1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
disparea.setText(area.getText());
}
}
);
JButton button2 = new JButton("20文字取得");
button2.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
try{
disparea.setText(area.getText(0, 20));
}catch(BadLocationException e){
System.out.println("Bad Location Error!");
}
}
}
);
p.add(scrollpane1);
p.add(scrollpane2);
p.add(button1);
p.add(button2);
Container contentPane = getContentPane();
contentPane.add(p, BorderLayout.CENTER);
}
}
最終更新:2011年03月21日 08:29