JAVAボタンプレート、簡単なボタン実現
package gf;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class sir implements ActionListener {
JButton sj=new JButton(" ");
JButton chy=new JButton(" ");
JButton cq=new JButton(" ");
JTextField tf=new JTextField(10);//
void go(){
JFrame jf=new JFrame(" ");
JPanel p=new JPanel();
jf.add(p,"South");
p.setBackground(Color.green);//setBackground
sj.setBackground(Color.white);
chy.setBackground(Color.yellow);
chy.setForeground(Color.pink);
cq.setForeground(Color.red);//setForeground ,
tf.setForeground(Color.blue);
p.add(sj);
p.add(chy);
p.add(cq);
jf.add(tf);// ,
sj.addActionListener(this);
chy.addActionListener(this);
cq.addActionListener(this);
jf.setSize(500, 200);
jf.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource( )==sj) tf.setText(" ");
if (e.getSource( )==chy) tf.setText(" ");
if (e.getSource( )==cq) tf.setText(" ");
}
public static void main(String[] args) {
sir x=new sir();
x.go();
}
}
/*重点内容1は、ボタンに(フォントと背景)色2を加えたもので、出力したいフォントに色があればSystem.out.println();out|をerrに変更できますが、赤いにすぎません*/