中国石油大学北京 石油工程学院 黄开浪
import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider;
import javax.swing.WindowConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class drawcar extends JFrame { Graphics g;
Container container;
JSlider jsliter11=new JSlider(); ImageIcon icon=new
ImageIcon(\); //我笔记本Tomcat服务器的照片;
Image img=icon.getImage();
JButton jButton1=new JButton(\开始\); JButton jButton2=new JButton(\暂停\); drawpicture dra; int x1=0; int y1=0;
Boolean flag=true; public drawcar() {
picture(); }
public void picture() {
jsliter11.setMaximum(100); jsliter11.setMinimum(1); jsliter11.setValue(5); dra=new drawpicture();
jsliter11.addChangeListener(new javax.swing.event.ChangeListener() {
public void
stateChanged(javax.swing.event.ChangeEvent e) {
dra.repaint(); }
石油工程学院 黄开浪
中国石油大学北京 石油工程学院 黄开浪
});
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setBounds(500,50,500,500); container=getContentPane(); setTitle(\迷你小车(黄开浪)\);
container.add(dra,BorderLayout.CENTER);
container.add(jsliter11,BorderLayout.NORTH); JPanel jpanel2=new JPanel();
jpanel2.setLayout(new FlowLayout(10, 10,10)); jpanel2.add(jButton1);jpanel2.add(jButton2); container.add(jpanel2,BorderLayout.SOUTH);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
flag=true;
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
while(flag) {
if(x1<500)
{
x1=x1+20; }
else { x1=0; } try{
Thread.sleep(100); }
catch (InterruptedException e) {
// TODO 自动生成的 catch 块 e.printStackTrace(); }
dra.repaint(); }
石油工程学院 黄开浪
中国石油大学北京 石油工程学院 黄开浪
}
} });
thread.start(); } });
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
flag=false; } }); }
class drawpicture extends Canvas {
public void paint(Graphics g) {
super.paint(g);
Graphics2D gd=(Graphics2D) g; int newx=0;
int newy=0;
float value=jsliter11.getValue();
newx=(int)(value*img.getWidth(this)/100); newy=(int)(value*img.getHeight(this)/100); //gd.rotate(Math.toRadians(5));
gd.drawImage(img,x1,y1,newx,newy,this); } }
public static void main(String args[]) {
new drawcar().setVisible(true); }
石油工程学院 黄开浪
中国石油大学北京 石油工程学院 黄开浪
3、
import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color;
import java.awt.Container; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Paint; import java.awt.Stroke; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.text.StyledEditorKit.BoldAction;
public class tuiyou extends JFrame {
Graphics g;
石油工程学院 黄开浪
中国石油大学北京 石油工程学院 黄开浪
JButton jButton1=new JButton(\增加选手\); JButton jButton3=new JButton(\删除选手\); JButton jButton2=new JButton(\画图\); drawpicture dra;
DefaultTableModel defaultModel = null; JTable jTable1; int x;
String col[]={\人数\,\竞选一号\,\竞选二号\,\竞选三号\};
String row[][]={{\人数\,\竞选一号\,\竞选二号\,\竞选三号\},{\票数\,\,\,\}}; public void main() {
new tuiyou(); }
/*2 编写一个班级推选优秀生的软件,
* 可列出参与推优的学生名单,能够显示当前投票人数以及每名候选者得票数, * 如果同时能够图形化显示得票数更佳。*/ public tuiyou() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle(\班级推优\);
Container cn=getContentPane(); setLayout(new BorderLayout()); setBounds(500,100,850,500); JPanel jPanel=new JPanel();
jPanel.setLayout(new GridLayout(2,1));
defaultModel=new DefaultTableModel(row,col); jTable1=new JTable(defaultModel);
jPanel.add(jTable1.getTableHeader()); jPanel.add(jTable1);
cn.add(jTable1,BorderLayout.NORTH); dra=new drawpicture();
cn.add(dra,BorderLayout.CENTER); JPanel jPanel2=new JPanel();
jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
jPanel2.add(jButton1);jPanel2.add(jButton3);jPanel2.add(jButton2); cn.add(jPanel2,BorderLayout.SOUTH);
System.out.println(dra.WIDTH+\+dra.HEIGHT); x=jTable1.getColumnCount()-1;
jButton1.addActionListener(new ActionListener() {
@Override
石油工程学院 黄开浪