给一个对button得事件处理:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.Date;
//import java.util.Date;public class test1
extends JFrame
implements ActionListener {
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
JTextArea text;
JButton button1, button2, button3;
public test1() {
super("aa");
Container c = getContentPane();
c.setLayout(new FlowLayout());
text = new JTextArea("中国人", 5, 10);
button1 = new JButton("正体");
button2 = new JButton("斜体");
button3 = new JButton("粗体");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
c.add(new JScrollPane(text));
c.add(button1);
c.add(button2);
c.add(button3);
text.setFont(new Font("宋体", Font.PLAIN, 13));
setSize(300, 200);
setVisible(true);
// new Date().valueOf();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
} } public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
text.setFont(new Font("华文彩云", Font.PLAIN, 13));
text.setForeground(Color.red);
System.out.println(1);
}
else if (e.getSource() == button2) {
text.setFont(new Font("宋体", Font.ITALIC, 13));
System.out.println(2);
}
else if (e.getSource() == button3) {
text.setFont(null);
text.setFont(new Font("黑体", Font.BOLD, 13));
System.out.println(3);
}
} public static void main(String args[]) {
test1 cz = new test1();
cz.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(48, 78, 295, 130));
this.getContentPane().add(jScrollPane1, null);
jPanel1.setSize(300,200);
jScrollPane1.getViewport().add(jPanel1, null);
}
}
import java.awt.event.*;
import javax.swing.*;
import java.sql.Date;
//import java.util.Date;public class test1
extends JFrame
implements ActionListener {
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
JTextArea text;
JButton button1, button2, button3;
public test1() {
super("aa");
Container c = getContentPane();
c.setLayout(new FlowLayout());
text = new JTextArea("中国人", 5, 10);
button1 = new JButton("正体");
button2 = new JButton("斜体");
button3 = new JButton("粗体");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
c.add(new JScrollPane(text));
c.add(button1);
c.add(button2);
c.add(button3);
text.setFont(new Font("宋体", Font.PLAIN, 13));
setSize(300, 200);
setVisible(true);
// new Date().valueOf();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
} } public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
text.setFont(new Font("华文彩云", Font.PLAIN, 13));
text.setForeground(Color.red);
System.out.println(1);
}
else if (e.getSource() == button2) {
text.setFont(new Font("宋体", Font.ITALIC, 13));
System.out.println(2);
}
else if (e.getSource() == button3) {
text.setFont(null);
text.setFont(new Font("黑体", Font.BOLD, 13));
System.out.println(3);
}
} public static void main(String args[]) {
test1 cz = new test1();
cz.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(48, 78, 295, 130));
this.getContentPane().add(jScrollPane1, null);
jPanel1.setSize(300,200);
jScrollPane1.getViewport().add(jPanel1, null);
}
}
还有什么接收器那,还有函数getcontentpane()
gettext(),getselectedtext()
都是什么意思,怎么用呀?
还有loop什么意思,怎么用?
我不知道的东西太多了,分数不够,可以再加!