问答题
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
*/
public class ex11_3 extends JApplet {
private JButton jb = new JButton("OK");
private JTextPane jtp = new JTextPane();
private JTextField jtf=new JTextField(8);
private int n=15;
public void init() {
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
n=jtf.getText();
jtp.setText("");
for(int i = n-1; i>=0;i--){
String s = "";
for(int j = 0; j < i; j++)
s += " ";
for(int j = 0; j < n; j++)
s += "* ";
jtp.setText(s+"\n");
}
}
});
Container cp = getContentPane();
cp.add(BorderLayout.NORTH,jtf);
cp.add(BorderLayout.CENTER,new JScrollPane(jtp));
cp.add(BorderLayout.SOUTH, jb);
}
public static void main(String[] args) {
ex11_3 obj11_3=new ex11_3();
String str = obj11_3.getClass().toString();
if(str.indexOf("class") != -1)
str = str.substring(6);
JFrame frm = new JFrame(str);
frm.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
frm.getContentPane().add(obj11_3);
frm.setSize(300, 500);
frm.setVisible(true);
}
}
ex11_3.html