请前辈评论applet编码风格,还能否优化
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class Button extends JApplet {
private static final long serialVersionUID=123456L
JButton b1 = new JButton("向左走");
JButton b2 = new JButton("向右走");
public void init() {
this.getContentPane();
run(this);
this.setVisible(true);
} public void run(JApplet applet) {
container();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//响应关闭按钮 } private void container() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b1);
cp.add(b2);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class Button extends JApplet {
private static final long serialVersionUID=123456L
JButton b1 = new JButton("向左走");
JButton b2 = new JButton("向右走");
public void init() {
this.getContentPane();
run(this);
this.setVisible(true);
} public void run(JApplet applet) {
container();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//响应关闭按钮 } private void container() {
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b1);
cp.add(b2);
}
}
解决方案 »
- Java中的gui设计问题,想设计一个界面,左面显示一列按钮,右面是界面,然后点击不同的按钮右面界面是不同的,这个如何做
- 多线程问题请教
- Java里Tab的KEYCODE是啥啊
- 再来讨论一下Fackbook的那道面试题
- 单选按钮为什么出来两次相应的问题
- 添加背景图片的问题,急呀,在线等!!!
- java保留字的替换单词一般是什么?
- 请问如何监测某一主机是否在某一端口进行监听?
- 关于JTextField,UP有分,分不够再加!
- 表数据显示类JTable
- 学习Thinking In Java时有个困惑:为什么是覆盖基类的方法而不是实现接口的方法
- 求助关于ComponentAdapter的componentResized方法
我怀疑我的入口初始化有概念上的错误,一时也想不明白,因为eclipse上运行也正常,请哪位前辈点睛,急啊~~~~~~
public void init()
{ Button objButton =new Button();
this.setSize(500, 200);
objButton.getContentPane();
run(objButton);
objButton.setVisible(true);
}
import javax.swing.JButton;
import java.awt.event.*;
import java.awt.Font;
import java.awt.Color;
//import java.util.Vector;
public class MyProject extends JApplet
{
private static final long serialVersionUID = 234567L ;
private javax.swing.JPanel jContentPanel = null;
private MyButton leftButton = null;
private MyButton rightButton = null; public void init() {
this.setSize(500,200);
this.setContentPane(getJContentPanel()); }...........问题解决了,采用这种方法比较好~!!!
BufferedImage bi = (BufferedImage) createImage(imgWidth, imgHeight);
/*
* BufferedImage bi = new BufferedImage( img.getWidth(null),
* img.getHeight(null), BufferedImage.TYPE_INT_RGB);
*/ Graphics2D g2 = bi.createGraphics();
g2.clipRect(rectX, rectY, rectWidth, rectHeight);
g2.drawImage(img, null, null);
int moveX = rectX > 0 ? rectX : 0;
int moveY = rectY > 0 ? rectY : 0;
int cutWidth = rectX + rectWidth > imgWidth ? rectWidth
- ((rectX + rectWidth) - imgWidth) : rectWidth;
int cutHeight = rectY + rectHeight > imgHeight ? rectHeight
- ((rectY + rectHeight) - imgHeight) : rectHeight;
bi = bi.getSubimage(moveX, moveY, cutWidth, cutHeight); FileOutputStream out = null;
try {
out = new FileOutputStream(s);
} catch (java.io.FileNotFoundException io) {
System.out.println("File Not Found");
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false);
encoder.setJPEGEncodeParam(param);
try {
encoder.encode(bi);
out.close();
} catch (java.io.IOException io) {
System.out.println("IOException");
}
}
}