Topic: Applet中怎样在初始化的时候显示按钮??? |
Print this page |
1.Applet中怎样在初始化的时候显示按钮??? | Copy to clipboard |
Posted by: zc_218 Posted on: 2005-12-02 15:43 我设置的按钮在程序初始化的时候无法显示,只有当鼠标单击按钮所在位置时才出现,请问怎样解决???? |
2.Re:Applet中怎样在初始化的时候显示按钮??? [Re: zc_218] | Copy to clipboard |
Posted by: yingjia53 Posted on: 2005-12-04 13:35 把你得程序写出来· |
3.Re:Applet中怎样在初始化的时候显示按钮??? [Re: zc_218] | Copy to clipboard |
Posted by: Infinite Posted on: 2005-12-06 13:05 这个问题我在编程的时候也遇到了,同样请教中~~如下我的程序: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main extends JFrame { final static int WIDTH=600,HEIGHT=800; final static int MH=400,MW=300; static double a=1.0; static int n; static double x,x1; JTextField tone=new JTextField("1.0",4); JTextField ttwo=new JTextField(4); Container content=getContentPane(); //========= define the function =============== double f(double i){ i=a; return 5/(i*i+x*x); //return MH-(30*5/(i*i+x*x)); } //========= double f1(double i){ i=a; return 5/(i*i+x1*x1); //return MH-(30*5/(i*i+x1*x1)); } //========= double l(){ double sum=0; double temp=1.0; double xk,xj; for (int k=0;k<=n ;k++ ) { for (int j=0;j<=n;j++) { if(j==k) j++; xk=-5+k*(double)10/(double)n; xj=-5+j*(double)10/(double)n; temp=temp*((x-xj)/(xk-xj)); } sum=sum+f(a)*temp; temp=1.0; } return sum; } //========= double ltwo(){ double sum=0; double temp=1.0; double xk,xj; for (int k=0;k<=n ;k++ ) { for (int j=0;j<=n;j++) { if(j==k) j++; xk=-5+k*((double)10/(double)n); xj=-5+j*((double)10/(double)n); temp=temp*((x1-xj)/(xk-xj)); } sum=sum+f(a)*temp; temp=1.0; } return sum; } //========= construct function =============== public Main() { JPanel pone=new JPanel(); JButton a=new JButton("a"); JButton n=new JButton("n"); JButton submit=new JButton("submit"); //setBackground(new Color(0x71,0xA6,0xF4)); content.setLayout(new FlowLayout()); //========== pone init ============================= pone.setLayout(new GridLayout(1,4)); submit.addActionListener(new DrawListener()); submit.setBackground(new Color(0x93,0xC3,0xBB)); a.setBackground(new Color(0x93,0xC3,0xBB)); n.setBackground(new Color(0x93,0xC3,0xBB)); pone.add(a); pone.add(tone); pone.add(n); pone.add(ttwo); pone.add(submit); //======================================================== content.add(pone); setLocation(320,100); setSize(WIDTH,HEIGHT); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void paint(Graphics g) { int number=0; //=========== draw the "reference frame" =============== g.drawString("0",MW+5,MH+14); // 0 g.drawLine(20,MH,WIDTH-20,MH); //x below 25=1CM g.drawLine(WIDTH-20,MH,WIDTH-25,MH+5); g.drawLine(WIDTH-20,MH,WIDTH-25,MH-5); g.drawString("x",WIDTH-20,MH+12); g.drawString("5",MW+25*5,MH+12); g.drawLine(MW+25*5,MH,MW+25*5,MH-5); g.drawString("-5",MW-25*5,MH+12); g.drawLine(MW-25*5,MH,MW-25*5,MH-5); g.drawLine(MW,60,MW,HEIGHT-40); //y below 30=1CM g.drawLine(MW,60,MW-5,60+5); g.drawLine(MW,60,MW+5,60+5); g.drawString("y",MW-10,65); g.drawString("5",MW-10,MH-30*5); g.drawLine(MW,MH-30*5,MW+5,MH-30*5); g.drawString("-5",MW-12,MH+30*5); g.drawLine(MW,MH+30*5,MW+5,MH+30*5); g.drawString("10",MW-15,MH-30*10); g.drawLine(MW,MH-30*10,MW+5,MH-30*10); g.drawString("-10",MW-18,MH+30*10); g.drawLine(MW,MH+30*10,MW+5,MH+30*10); //========= asume a=1 draw the line ============ for (int count=0;count<=25*10;) { g.setColor(Color.red); int temp; x=-5+((double)count/(double)25); temp=count; x1=-5+((double)++count/(double)25); g.drawLine(-25*5+temp+MW,(int)(MH-30*f(a)),-25*5+count+MW,(int)(MH-30*f1(a))); //========= draw the line coped with ============== if(ttwo.getText().length()!=0) { g.setColor(Color.blue); g.drawLine(-25*5+temp+MW,(int)(MH-30*l()),-25*5+count+MW,(int)(MH-30*ltwo())); } } //========= description ========================== Font font=new Font("隶书",Font.BOLD,24); g.setFont(font); g.setColor(Color.red); g.drawString("Red : 原函数",50,100); g.setColor(Color.blue); g.drawString("Blue : 拟合函数",50,120); //========= draw the line coped with ============== /* g.setColor(new Color(0x00,0x99,0x00)); if(ttwo.getText().length()!=0) { for (int count=0;count<=25*10 ; ) { int temp; x=-5+((double)count/(double)25); temp=count; x1=-5+((double)++count/(double)25); g.drawLine(-25*5+temp+MW,(int)l(a),-25*5+count+MW,(int)ltwo(a)); } } else { } */ } //======= draw lintening ================== class DrawListener implements ActionListener { public void actionPerformed(ActionEvent e) { double one; int two; if(tone.getText().length()==0&&ttwo.getText().length()==0) {JOptionPane.showMessageDialog(null,"please input aviliable number");} if(tone.getText().length()!=0) {one=Double.parseDouble(tone.getText());a=one;} if(ttwo.getText().length()!=0) {two=Integer.parseInt(ttwo.getText()); n=two;} System.out.println("a="+tone.getText()); content.repaint(); repaint(); //content.setBackground(new Color(0x71,0xA6,0xF4)); } } //======= draw ====================== public static void main(String[] args) { Main get=new Main(); get.setTitle("demo version1.0 (made by Infinite)"); get.setVisible(true); } } |
4.Re:Applet中怎样在初始化的时候显示按钮??? [Re: zc_218] | Copy to clipboard |
Posted by: Infinite Posted on: 2005-12-06 13:18 |
5.Re:Applet中怎样在初始化的时候显示按钮??? [Re: zc_218] | Copy to clipboard |
Posted by: shibin20011983 Posted on: 2005-12-06 20:43 对呀,我编applet和frame的时候都这样的,运行的时候看不见按钮,只要动一下界面就可以出来了,这是为什么? |
6.Re:Applet中怎样在初始化的时候显示按钮??? [Re: zc_218] | Copy to clipboard |
Posted by: 缥缈水云间 Posted on: 2006-01-09 20:42 上次我也遇到类似的情况,后来解决了,可现在想不起来了哦.等想起来再告诉你吧. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |