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

📄 webmath.java

📁 基于web的数学公式编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package webmath;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.Timer;
import java.net.*;

public class Webmath extends Applet implements MouseListener
{

	private boolean isStandalone  = false;
	Icon			msup;							  // 上标按钮所对应的图标
	Icon			msub;
	Icon			mfrac;
	Icon			msqrt;
	Icon			mroot;
	Icon			mintsubsup;
	Icon			msumunderover;
	Icon			mprodunderover;
	Icon			mover;
	Icon			munder;
	Icon			munderover;
	Icon			mintsubsup2;
	Icon			msubsup;
	Icon			kuohao;
	Icon			mtable;
	Icon			sign;
	URL			 codebase;
	Cursor		  mycursor;
	BorderLayout	borderLayout1 = new BorderLayout();
	Panel		   panel2		= new Panel();
	JToolBar		jToolBar1	 = new JToolBar();
	JButton		 jButton1	  = new JButton();
	JButton		 jButton2	  = new JButton();
	JButton		 jButton3	  = new JButton();
	JButton		 jButton4	  = new JButton();
	JButton		 jButton5	  = new JButton();
	JButton		 jButton6	  = new JButton();
	JButton		 jButton7	  = new JButton();
	JButton		 jButton8	  = new JButton();
	JButton		 jButton9	  = new JButton();
	JButton		 jButton10	 = new JButton();
	JButton		 jButton11	 = new JButton();
	JButton		 jButton12	 = new JButton();
	JButton		 jButton13	 = new JButton();
	JButton		 jButton14	 = new JButton();
	JButton		 jButton15	 = new JButton();
	BorderLayout	borderLayout2 = new BorderLayout();
	FlowLayout	  flowLayout1   = new FlowLayout();
	Panel1		  panel1		= new Panel1(this);

	// Get a parameter value
	public String getParameter(String key, String def)
	{

		return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def);
	}

	// Construct the applet
	public Webmath()
	{

	}

	// Initialize the applet
	public void init()
	{

		try
		{
			codebase = this.getCodeBase();
			isourcodebase();
			seticon();
			jbInit();
			panel1.addMouseListener(this);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		panel1.requestFocus();
		ActionListener listener2 = new Showcursor(this);
		Timer t = new Timer(500, listener2);
		t.start();
	}

	void seticon() throws MalformedURLException
	{

		URL url = getCodeBase();
		Image up;
		up = getImage(new URL(url, "images/msup.gif"));
		msup = new ImageIcon(up);
		up = getImage(new URL(url, "images/msub.gif"));
		msub = new ImageIcon(up);
		up = getImage(new URL(url, "images/msqrt.gif"));
		msqrt = new ImageIcon(up);
		up = getImage(new URL(url, "images/mfrac.gif"));
		mfrac = new ImageIcon(up);
		up = getImage(new URL(url, "images/mroot.gif"));
		mroot = new ImageIcon(up);
		up = getImage(new URL(url, "images/mintsubsup.gif"));
		mintsubsup = new ImageIcon(up);
		up = getImage(new URL(url, "images/msumunderover.gif"));
		msumunderover = new ImageIcon(up);
		up = getImage(new URL(url, "images/mprodunderover.gif"));
		mprodunderover = new ImageIcon(up);
		up = getImage(new URL(url, "images/msup.gif"));
		msup = new ImageIcon(up);
		up = getImage(new URL(url, "images/mover.gif"));
		mover = new ImageIcon(up);
		up = getImage(new URL(url, "images/munder.gif"));
		munder = new ImageIcon(up);
		up = getImage(new URL(url, "images/munderover.gif"));
		munderover = new ImageIcon(up);
		up = getImage(new URL(url, "images/msubsup.gif"));
		msubsup = new ImageIcon(up);
		up = getImage(new URL(url, "images/kuohao.gif"));
		kuohao = new ImageIcon(up);
		up = getImage(new URL(url, "images/mtable.gif"));
		mtable = new ImageIcon(up);
		up = getImage(new URL(url, "images/sign.gif"));
		sign = new ImageIcon(up);
		jButton1.setIcon(msup);
		jButton2.setIcon(msub);
		jButton3.setIcon(mfrac);
		jButton4.setIcon(msqrt);
		jButton5.setIcon(mroot);
		jButton6.setIcon(mintsubsup);
		jButton7.setIcon(msumunderover);
		jButton8.setIcon(mprodunderover);
		jButton9.setIcon(mover);
		jButton10.setIcon(munder);
		jButton11.setIcon(munderover);
		jButton12.setIcon(msubsup);
		jButton13.setIcon(kuohao);
		jButton14.setIcon(mtable);
		jButton15.setIcon(sign);
	}

	// Component initialization
	private void jbInit() throws Exception
	{

		this.setBackground(SystemColor.inactiveCaptionBorder);
		this.setLayout(borderLayout1);
		panel2.setLayout(borderLayout2);
		panel2.setBackground(Color.yellow);
		jButton1.addActionListener(new Webmath_jButton1_actionAdapter(this));
		jButton2.setToolTipText("");
		jButton2.setActionCommand("jButton2");
		jButton2.setText("下标");
		jButton2.addActionListener(new Webmath_jButton2_actionAdapter(this));
		jButton3.setToolTipText("");    jButton3.setText("分数");
		jButton3.addActionListener(new Webmath_jButton3_actionAdapter(this));
		jButton4.setText("平方根");
		jButton4.addActionListener(new Webmath_jButton4_actionAdapter(this));
		jButton5.setText("多次方根");
		jButton5.addActionListener(new Webmath_jButton5_actionAdapter(this));
		jButton6.setText("积分");
		jButton6.addActionListener(new Webmath_jButton6_actionAdapter(this));
		jButton14.setRequestFocusEnabled(false);
		jButton14.setText("矩阵");
		jButton14.addActionListener(new Webmath_jButton14_actionAdapter(this));
		jButton13.setRequestFocusEnabled(false);
		jButton13.setText("括号");
		jButton13.addActionListener(new Webmath_jButton13_actionAdapter(this));
		jButton12.setText("上下标");
		jButton12.addActionListener(new Webmath_jButton12_actionAdapter(this));
		jButton11.setText("上下限");
		jButton11.addActionListener(new Webmath_jButton11_actionAdapter(this));
		jButton10.setText("下限");
		jButton10.addActionListener(new Webmath_jButton10_actionAdapter(this));
		jButton8.setText("求积");
		jButton8.addActionListener(new Webmath_jButton8_actionAdapter(this));
		jButton7.setText("求和");
		jButton7.addActionListener(new Webmath_jButton7_actionAdapter(this));
		jButton9.addActionListener(new Webmath_jButton9_actionAdapter(this));
		jButton15.setRequestFocusEnabled(false);    jButton15.setToolTipText("");
		jButton15.setFocusPainted(true);    jButton15.setText("符号");
		jButton15.addActionListener(new Webmath_jButton15_actionAdapter(this));
		jToolBar1.setRequestFocusEnabled(false);
		panel1.setLayout(flowLayout1);
		panel1.setBackground(new Color(230, 250, 200));
		panel1.addKeyListener(new Webmath_panel1_keyAdapter(this));
		panel1.addMouseMotionListener(new Webmath_panel1_mouseMotionAdapter(this));
		panel1.addMouseListener(new Webmath_panel1_mouseAdapter(this));
		jButton1.setText("上标");    jButton9.setText("上限");    jToolBar1.add(jButton1, null);
		jToolBar1.add(jButton2, null);
		jToolBar1.add(jButton3, null);
		jToolBar1.add(jButton4, null);
		jToolBar1.add(jButton5, null);
		jToolBar1.add(jButton6, null);
		jToolBar1.add(jButton7, null);
		jToolBar1.add(jButton8, null);
		jToolBar1.add(jButton9, null);
		jToolBar1.add(jButton10, null);
		jToolBar1.add(jButton11, null);
		jToolBar1.add(jButton12, null);
		jToolBar1.add(jButton13, null);
		jToolBar1.add(jButton14, null);
		jToolBar1.add(jButton15, null);
		this.add(panel1, BorderLayout.CENTER);
		this.add(panel2, BorderLayout.NORTH);
		panel2.add(jToolBar1, BorderLayout.SOUTH);
		Color buttonbkcolor = new Color(192, 192, 192);
		jButton1.setBackground(buttonbkcolor);
		jButton2.setBackground(buttonbkcolor);
		jButton3.setBackground(buttonbkcolor);
		jButton4.setBackground(buttonbkcolor);
		jButton5.setBackground(buttonbkcolor);
		jButton6.setBackground(buttonbkcolor);
		jButton7.setBackground(buttonbkcolor);
		jButton8.setBackground(buttonbkcolor);
		jButton9.setBackground(buttonbkcolor);
		jButton10.setBackground(buttonbkcolor);
		jButton11.setBackground(buttonbkcolor);
		jButton12.setBackground(buttonbkcolor);
		jButton13.setBackground(buttonbkcolor);
		jButton14.setBackground(buttonbkcolor);
		jButton15.setBackground(buttonbkcolor);
	}

	// Get Applet information
	public String getAppletInfo()
	{

		return "Applet Information";
	}

	// Get parameter info
	public String[][] getParameterInfo()
	{

		return null;
	}

	public void panel1_keyTyped(KeyEvent e)
	{

		char astring;
		astring = e.getKeyChar();
		int keycode = e.getKeyCode();
		if (astring == '\b')
		{
			panel1.deleteElement();
		}
		else if (astring == '\n')
		{
		}
		else if (astring == '\n')
		{
		}
		else
		{
			panel1.keydown(astring);
		}
	}

	void panel1_mousePressed(MouseEvent e)
	{

		int x, y;
		x = e.getX();
		y = e.getY();
		panel1.mousePressed(x, y);
		panel1.requestFocus();
	}

	void panel1_mouseReleased(MouseEvent e)
	{

		int x, y;
		x = e.getX();
		y = e.getY();
		panel1.mouseReleased(x, y);
	}

	void panel1_mouseDragged(MouseEvent e)
	{

		int x, y;
		x = e.getX();
		y = e.getY();
		panel1.mouseDragged(x, y);
	}

	public void drawcursor()
	{

		panel1.repaint();
	}

	void jButton1_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(1);
		panel1.requestFocus(true);
		panel1.requestFocusInWindow();
	}

	void jButton2_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(2);
	}

	void jButton3_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(3);
	}

	void jButton4_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(4);
	}

	void jButton5_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(5);
	}

	void jButton6_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(6);
	}

	void jButton7_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(7);
	}

	void jButton8_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(8);
	}

	void jButton9_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(9);
	}

	void jButton10_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(10);
	}

	void jButton11_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(11);
	}

	void jButton12_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(12);
	}

	void jButton13_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(13);
	}

	void jButton14_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(14);
	}

	void jButton15_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(15);
	}

	void button1_actionPerformed(ActionEvent e)
	{

		panel1.buttondown(0);
	}

	void isourcodebase()
	{ // 判断是不是本地调用该applet,如果不是本地调用则该applet不能被使用

		String codebase;
		String ourcodebase = "a";
		URL cb = getCodeBase();
		codebase = cb.getHost();
		System.out.println(codebase);
		if (!codebase.equals(ourcodebase))
		{
			// System.out.println("Warning ! A stolen Applet.");
			// System.exit(1);
		}
	}

	public String getxmlcode()
	{

		return this.panel1.getxmlcode();
	}

	public void mouseMoved(MouseEvent e)
	{

	}

	public void mouseClicked(MouseEvent e)
	{

	}

	public void mouseEntered(MouseEvent e)

⌨️ 快捷键说明

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