老师给布置个任务,点击放大缩小按纽的话,窗体会水平放大缩小,(就是说窗体内10cm长的横线点击放大按纽的话会按一定比例放大到20cm;再点放大到40cm)具体怎么实现啊,各位大侠帮帮忙,万分感谢!

解决方案 »

  1.   

    绘制时设置 Graphics 对象的 scale 属性
      

  2.   

    一楼的不好意思啊,我问题没有说明白,
    我想问的是在SWT中怎么实现,而不是用awt,希望帮忙解答
      

  3.   

     刚写的,还是热的哪。import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.layout.RowLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.SWT;public class Change extends SelectionAdapter {
    static int width = 500; static int height = 400; static Button zoomIn; static Button zoomOut; static Shell shell; public static void main(String args[]) {
    Change change = new Change();
    Display display = new Display();
    shell = new Shell(display);
    shell.setLayout(new RowLayout());
    zoomIn = new Button(shell, SWT.PUSH | SWT.CENTER);
    zoomIn.addSelectionListener(change);
    zoomIn.setText("缩小");
    zoomOut = new Button(shell, SWT.PUSH | SWT.CENTER);
    zoomOut.addSelectionListener(change);
    zoomOut.setText("放大");
    shell.setSize(width, height);
    shell.setVisible(true);
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
    display.sleep();
    }
    }
    shell.dispose();
    display.dispose();
    } public void widgetSelected(SelectionEvent arg0) {
    if (arg0.getSource() == zoomIn) {
    width -= 50;
    } else if (arg0.getSource() == zoomOut) {
    width += 50;
    }
    shell.setSize(width, height);
    }
    }