⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicsdemo.java

📁 使用java application 的共享白板系统
💻 JAVA
字号:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

import java.io.*;

public class GraphicsDemo extends JFrame implements Runnable{
   
    private static final long serialVersionUID = 1652129620007407549L;
    GraphicsBorderedCanvas c;
    DrawnShape newshape; 
	public GraphicsDemo(String title) {
		super(title);
		Container cp = this.getContentPane();
		JPanel p = new JPanel(true);
		p.setLayout(new BorderLayout());
		cp.add(p);
		// Create the canvas in which the
		// drawing will be done.
		c = new GraphicsBorderedCanvas();
		c.setPreferredSize(new Dimension(450, 500));
		
		// Create the border and associate it with the canvas
		Border bd = new EdgedBorder(c.getBackground());
		c.setBackground(Color.white);
		c.setBorder(bd);
		
		p.add(c, BorderLayout.CENTER);

		// Create the right-hand panel which
		// holds the color buttons
		GraphicsDemoPane gp = new GraphicsDemoPane();
		p.add(gp, BorderLayout.EAST);

		// Connect panel to canvas so that 
		// it can enable/disable buttons
		c.addPropertyChangeListener(gp);

		// Connect the canvas to the panel
		// so that it can action button presses
		gp.setDrawingArea(c);

		// Select the initial color and shape
		// from the button panel.
		gp.selectTools();
	}
          
          public void run()
	{
		try
		{
			///////先用UDP通讯,传递组播号
                        
                        InetAddress inetaddress=InetAddress.getByName("235.0.0.125");
//			加入多播组,接收并处理msg
			MulticastSocket multicastsocket2;
			multicastsocket2=new MulticastSocket(8000);
			multicastsocket2.joinGroup(inetaddress);
			
			
			while(true)
			{
				byte[] mes=new byte[20000];
				DatagramPacket datagrampacket=new DatagramPacket(mes,mes.length);
				multicastsocket2.receive(datagrampacket);
				
				ByteArrayInputStream buffers = new ByteArrayInputStream(mes);
				ObjectInputStream in = new ObjectInputStream(buffers);
                                
                                
				newshape=(DrawnShape)in.readObject();
				in.close();
				
                                 
                                c.drawingOps.add(newshape);
			        c.repaint();
                              
			}	
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
		
	}
				
	public static void main(String[] args) {
		GraphicsDemo f = new GraphicsDemo("电子白板");
		f.pack();
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				System.exit(0);
			}
		});
		
                    
                Thread thread=new Thread(f);
		thread.start();	
                    
                f.setVisible(true);
	}
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -