网络编程实验报告(7)

2019-08-03 14:54

private JLabel lb = new JLabel(\拖动测试对象\); private Thread th = new Thread(new dothread()); private boolean canmove = false; private Component com = null; private Point pt = new Point(); MyClass() { }

class dothread implements Runnable {

public void run() {

// TODO 自动生成方法存根 while (true) {

if (canmove) {

if (fm.getMousePosition() != null) {

fm.setLayout(null);

fm.setDefaultCloseOperation(3); fm.setBounds(300, 200, 450, 300); fm.addMouseListener(new mouselisten()); lb.setBounds(10, 10, 100, 25); // lb.hide(); th.start();

fm.getContentPane().add(lb); fm.show();

}

}

}

}

}

pt.x = fm.getMousePosition().x; pt.y = fm.getMousePosition().y; lb.setLocation(pt);

class mouselisten implements MouseListener {

public void mouseClicked(MouseEvent arg0) {

}

if (arg0.getButton() == 1) { } else { }

canmove = false; canmove = true;

public void mouseEntered(MouseEvent arg0) { }

public void mouseExited(MouseEvent arg0) { }

public void mousePressed(MouseEvent arg0) {

}

}

new MyClass();

public static void main(String[] args) { }

}

canmove = false;

public void mouseReleased(MouseEvent arg0) {

}

canmove = false;

8.计算器

package Frame;

public class Compute { public static void main(String args[]) { ComputeFrame s=new ComputeFrame(); }

}

////////////////////////////////////////////////////////////// package Frame;

import java.awt.*;

import java.awt.GridLayout;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import javax.swing.*;

public class ComputeFrame extends JFrame { private JPanel EditTextPanel,ButtonPanel; private JTextField input; private JButton numbutton[]; private JButton btnDot, btnPosMinus, btnBackspace, btnDivide1, btnEqual, btnClear; private JButton btnAdd, btnSubtract, btnMultiply, btnDivide; private JButton btnX2, btnX3, btnXY, btnSin, btnCos, btnTan, btnSqrt, btnN, btnLeft, btnRight; private int i; ComputeControler comControler; public ComputeFrame() { this.setBounds(300, 300, 400, 300); //this.DISPOSE_ON_CLOSE(this); setVisible(true); setLocation(400, 200); EditTextPanel=new JPanel(); ButtonPanel=new JPanel(); input =new JTextField(20); comControler=new ComputeControler(input); input.setHorizontalAlignment(JTextField.HEIGHT); input.setEditable(false); numbutton=new JButton[10]; for( i=0;i<10;i++) { numbutton[i]=new JButton(\ } btnDot=new JButton(\ btnPosMinus=new JButton(\ btnBackspace=new JButton(\ btnDivide1=new JButton(\

btnEqual=new JButton(\ btnClear=new JButton(\ btnAdd=new JButton(\ btnSubtract=new JButton(\ btnMultiply=new JButton(\ btnDivide=new JButton(\ btnLeft = new JButton(\ btnRight = new JButton(\ btnX2 = new JButton(\ btnX3 = new JButton(\ btnXY = new JButton(\ btnSqrt = new JButton(\ btnSin = new JButton(\ btnCos = new JButton(\ btnTan = new JButton(\ btnN = new JButton(\

EditTextPanel.add(input); //布局

ButtonPanel.setLayout(new GridLayout(6, 5));

ButtonPanel.add( btnLeft ).setForeground(Color.red); ButtonPanel.add( btnRight ).setForeground(Color.red); ButtonPanel.add( btnSin ).setForeground(Color.red); ButtonPanel.add( btnCos ).setForeground(Color.red); ButtonPanel.add( btnTan ).setForeground(Color.red);

ButtonPanel.add( btnX2 ).setForeground(Color.red); ButtonPanel.add( btnX3 ).setForeground(Color.red); ButtonPanel.add( btnXY ).setForeground(Color.red); ButtonPanel.add( btnSqrt ).setForeground(Color.red); ButtonPanel.add( btnN ).setForeground(Color.red);

ButtonPanel.add( numbutton[7] ).setForeground(Color.blue); numbutton[7].setBackground(Color.LIGHT_GRAY);

ButtonPanel.add( numbutton[8] ).setForeground(Color.blue); numbutton[8].setBackground(Color.LIGHT_GRAY);

ButtonPanel.add( numbutton[9] ).setForeground(Color.blue); numbutton[9].setBackground(Color.LIGHT_GRAY); ButtonPanel.add( btnAdd ).setForeground(Color.red); ButtonPanel.add( btnClear ).setForeground(Color.red);


网络编程实验报告(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:建筑工程施工技术与管理复习题答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: