为什么java中的JFrame不能显示
我写了一段代码,编译时没有错误,可运行不出来。代码如下:importjava.awt.*;importjavax.swing.*;importjava.awt.event...
我写了一段代码,编译时没有错误,可运行不出来。代码如下: 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); } }}不知道哪里有错误,运行时总是提示小程序启动失败。请高手指点下。万分感谢!
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询