
java 程序源代码.doc
17页实现翻页//源文件名:album.java//在下载源程序中的文件夹:0709相册import java.applet.*;import java.awt.*;import java.awt.event.*;public class album extends Applet implements ActionListener{ Image img[]; int j=0; String f; Label a1=new Label("文件名:"); Label a2=new Label(" "); Button btn1,btn2; public void init() { img = new Image[22]; setLayout(null); setBackground(Color.cyan); add(a1); add(a2); btn1= new Button("下一页"); btn2= new Button("上一页"); add(btn1); add(btn2); a1.setBounds(650,60,60,30); a2.setBounds(650,80,110,60); a2.setBounds(650,80,110,60); a1.setBackground(Color.cyan); a2.setBackground(Color.cyan); a2.setForeground(Color.red); Font ft = new Font("Times New Romon",1,20); a2.setFont(ft); btn1.setBounds(650,180,60,30); btn2.setBounds(650,240,60,30); btn1.addActionListener(this); btn2.addActionListener(this); for (int i=0;i<22;i++) { f="pic"+Integer.toString(i)+".jpg"; img[i]=getImage(getCodeBase(),f); } } public void paint (Graphics g) { f="pic"+Integer.toString(j)+".jpg"; a2.setText(f); int w=img[j].getWidth(this); int h=img[j].getHeight(this); g.drawImage(img[j],0,0,w,h,this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==btn1) { j++; if (j>21) j=0; } if(e.getSource()==btn2) { j--; if(j<0) j=21; } repaint(); }实现图行化界面package swt_jface.demo11; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.printing.PrintDialog; import org.eclipse.swt.printing.Printer; import org.eclipse.swt.printing.PrinterData; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; public class ImageViewer { Display display = new Display(); Shell shell = new Shell(display); Canvas canvas; Image image; String fileName; public ImageViewer() { shell.setText("Image viewer"); shell.setLayout(new GridLayout(1, true)); ToolBar toolBar = new ToolBar(shell, SWT.FLAT); ToolItem itemOpen = new ToolItem(toolBar, SWT.PUSH); itemOpen.setText("Open"); itemOpen.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { FileDialog dialog = new FileDialog(shell, SWT.OPEN); String file = dialog.open(); if (file != null) { if (image != null) image.dispose(); image = null; try { image = new Image(display, file); } catch (RuntimeException e) { } if (image != null) { fileName = file; } else { System.err.println( "Failed to load image from file: " + file); } canvas.redraw(); } } }); ToolItem itemPrintPreview = new ToolItem(toolBar, SWT.PUSH); itemPrintPreview.setText("Preview"); itemPrintPreview.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { ImagePrintPreviewDialog dialog = new ImagePrintPreviewDialog(ImageViewer.this); dialog.open(); } }); ToolItem itemPrint = new ToolItem(toolBar, SWT.PUSH); itemPrint.setText("Print"); itemPrint.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { print(); } }); canvas = new Canvas(shell, SWT.BORDER); canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); canvas.setLayoutData(new GridData(GridData.FILL_BOTH)); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { if (image == null) { e.gc.drawString("No image", 0, 0); } else { e.gc.drawImage(image, 0, 0); } } }); image = new Image(display, "C:/icons/scene.jpg"); fileName = "scene.jpg"; shell.setSize(500, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } void print() { PrintDialog dialog = new PrintDialog(shell); PrinterData printerData = dialog.open(); if (printerData == null) return; Printer printer = new Printer(printerData); print(printer, null); } void print(final Printer printer, PrintMargin printMargin) { if (image == null) return; final Point printerDPI = printer.getDPI(); final Point displayDPI = display.getDPI(); Sys。












