私の歴史と今

振り返ると恥ずかしくなるのが私の歴史。だけどそのときは真面目に書いていた訳でね。そんな今の私を書いていく。

Swing

コードを書いてみる。


public static void main(String[] args){
System.out.println("Hello World");
}

いけてるみたい。

Eclipseで書いてみよう。


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class SampleSwing {

/**
* @param args
*/
public static void main(String[] args) {

JFrame frame = new JFrame("SampleSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setAlwaysOnTop(true);
frame.setBackground(new Color(100, 200, 100));
frame.setBounds(100, 100, 500, 200);
frame.setFocusable(true);
frame.setTitle("mota5");

final JLabel label = new JLabel("mota5mota5mota5mota5mota5mota5mota5mota5mota5mota5mota5mota5mota5mota5");
final JButton addButton = new JButton("add");
final JButton delButton = new JButton("del");
final JTextField textField = new JTextField("対象文字");
final JTextArea textArea = new JTextArea();
final JScrollPane scrollPane = new JScrollPane(textArea);

Container container = frame.getContentPane();
container.add(label, BorderLayout.NORTH);
container.add(addButton, BorderLayout.WEST);
container.add(delButton, BorderLayout.EAST);
container.add(scrollPane, BorderLayout.CENTER);
container.add(textField, BorderLayout.SOUTH);

// event
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
textArea.setText(textArea.getText() + textField.getText());
}
});
delButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
textArea.setText(textArea.getText().replaceAll("\\Q" + textField.getText() + "\\E", ""));
} catch (RuntimeException e) {
textArea.setText(textArea.getText() + "\nうはwww" + e.getMessage());
}
}
});

//
frame.setVisible(true);
}
}

うむ