JAVA中box在Frame中显示不完_为什么java中的JFrame不能显示

我写了一段代码,编译时没有错误,可运行不出来。代码如下:importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.lang.*;importjava.app...

我写了一段代码,编译时没有错误,可运行不出来。代码如下: import java.awt.*;import javax.swing.*;import java.awt.event.*; import java.awt.geom.*;import java.lang.*;import java.applet.*;public class c3_ extends JApplet implements ActionListener{ public static void main(String[] arg) { new c3_(); } public c3_() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame f=new JFrame("正方形的变换"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JRadioButton r1,r2,r3,r4; Container cp=f.getContentPane(); f.pack(); f.setVisible(true); r1=new JRadioButton("rotate"); r1.addActionListener(this); cp.add(r1); r2=new JRadioButton("translate"); cp.add(r2); r3=new JRadioButton("scale"); cp.add(r3); r4=new JRadioButton("shear"); cp.add(r4); r2.addActionListener(this); r3.addActionListener(this); r4.addActionListener(this); } double a,b; double c,d; public void init() {a=50; b=50; c=100; d=100; } public void paint(Graphics g) { super.repaint(); Graphics2D g2=(Graphics2D)g; Line2D.Double line1=new Line2D.Double(a,b,c,b); Line2D.Double line2=new Line2D.Double(a,d,c,d); Line2D.Double line3=new Line2D.Double(a,b,a,d); Line2D.Double line4=new Line2D.Double(c,b,c,d); g2.draw(line1); g2.draw(line2); g2.draw(line3); g2.draw(line4); } public void actionPerformed(ActionEvent e) {String rbt=e.getActionCommand(); if(rbt=="translate") {a=50+30; b=50+30; c=c+30; d=d+30; } if(rbt=="scale") {a=a*2; b=b*2; c=c*2; d=d*2; } if(rbt=="rotate") {a=a*Math.cos(15)-b*Math.sin(15); b=a*Math.sin(15)-b*Math.cos(15); c=c*Math.sin(15)-d*Math.cos(15); d=c*Math.cos(15)-d*Math.sin(15); } }}不知道哪里有错误,运行时总是提示小程序启动失败。请高手指点下。万分感谢!

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值