java applet 鼠标事件
通过applet字体显示颜色及显示的文本类容,在鼠标单击时显示文本,鼠标松开时清空文本这是颜色的代码importjava.applet.*;importjava.awt....
通过applet字体显示颜色 及显示的文本类容,在鼠标 单击时显示文本,鼠标松开时清空文本
这是颜色的代码
import java.applet.*;
import java.awt.*;
public class test extends Applet {
String tempString ;
Color tempColor;
Font tempFont= new Font ("����A jiushi ",Font.PLAIN,20);
public void init(){
tempString = getParameter("color");
if(tempString.equals("white"))
tempColor = new Color(255,255,255);
if(tempString.equals("blue"))
tempColor = new Color(0,0,255);
if(tempString.equals("pink"))
tempColor = new Color(255,175,175);
if(tempString.equals("black"))
tempColor = new Color(0,0,0);
if(tempString.equals("green"))
tempColor = new Color(0,255,0);
if(tempString.equals("yellow"))
tempColor = new Color(255,255,0);
}
public void paint(Graphics g ){
g.setColor(tempColor);
g.drawString(getParameter("String"), 10, 20);
}
}
加几个鼠标事件就行了
还有 html
<html>
<head>
<title> hello world </title>
</head>
<body>
<applet code ="test.class" width=150 height =25>
<param name="color" value="blue">
<param name="String" value ="welcome to my java Applet page!">
</applet>
</body>
</html>
帮忙小弟搞一下 谢谢! 展开
这是颜色的代码
import java.applet.*;
import java.awt.*;
public class test extends Applet {
String tempString ;
Color tempColor;
Font tempFont= new Font ("����A jiushi ",Font.PLAIN,20);
public void init(){
tempString = getParameter("color");
if(tempString.equals("white"))
tempColor = new Color(255,255,255);
if(tempString.equals("blue"))
tempColor = new Color(0,0,255);
if(tempString.equals("pink"))
tempColor = new Color(255,175,175);
if(tempString.equals("black"))
tempColor = new Color(0,0,0);
if(tempString.equals("green"))
tempColor = new Color(0,255,0);
if(tempString.equals("yellow"))
tempColor = new Color(255,255,0);
}
public void paint(Graphics g ){
g.setColor(tempColor);
g.drawString(getParameter("String"), 10, 20);
}
}
加几个鼠标事件就行了
还有 html
<html>
<head>
<title> hello world </title>
</head>
<body>
<applet code ="test.class" width=150 height =25>
<param name="color" value="blue">
<param name="String" value ="welcome to my java Applet page!">
</applet>
</body>
</html>
帮忙小弟搞一下 谢谢! 展开
2个回答
展开全部
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Test extends Applet
{
int i = 0;
String tempString;
Color tempColor;
Font tempFont = new Font("����A jiushi ", Font.PLAIN, 20);
public void init()
{
tempString = getParameter("color");
if (tempString.equals("white"))
tempColor = new Color(255, 255, 255);
if (tempString.equals("blue"))
tempColor = new Color(0, 0, 255);
if (tempString.equals("pink"))
tempColor = new Color(255, 175, 175);
if (tempString.equals("black"))
tempColor = new Color(0, 0, 0);
if (tempString.equals("green"))
tempColor = new Color(0, 255, 0);
if (tempString.equals("yellow"))
tempColor = new Color(255, 255, 0);
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
i = 1;
repaint();
}
public void mouseReleased(MouseEvent e)
{
i = 2;
repaint();
}
});
}
public void paint(Graphics g)
{
if (i == 1)
g.setColor(Color.black);
if (i == 2)
g.setColor(this.getBackground());
g.drawString(getParameter("String"), 10, 20);
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Test extends Applet
{
int i = 0;
String tempString;
Color tempColor;
Font tempFont = new Font("����A jiushi ", Font.PLAIN, 20);
public void init()
{
tempString = getParameter("color");
if (tempString.equals("white"))
tempColor = new Color(255, 255, 255);
if (tempString.equals("blue"))
tempColor = new Color(0, 0, 255);
if (tempString.equals("pink"))
tempColor = new Color(255, 175, 175);
if (tempString.equals("black"))
tempColor = new Color(0, 0, 0);
if (tempString.equals("green"))
tempColor = new Color(0, 255, 0);
if (tempString.equals("yellow"))
tempColor = new Color(255, 255, 0);
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
i = 1;
repaint();
}
public void mouseReleased(MouseEvent e)
{
i = 2;
repaint();
}
});
}
public void paint(Graphics g)
{
if (i == 1)
g.setColor(Color.black);
if (i == 2)
g.setColor(this.getBackground());
g.drawString(getParameter("String"), 10, 20);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是我写的,你运行一下吧,应该可以的哦
package Test;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class AppletMouse extends Applet implements MouseListener
{
private static final long serialVersionUID = 1L;
AppletMouse()
{
this.addMouseListener(this);
}
private void drawString(String string, int i, int j)
{
// TODO Auto-generated method stub
}
public static void main(String args[])
{
new AppletMouse();
}
public void mouseClicked(MouseEvent arg0)
{
}
public void mouseEntered(MouseEvent arg0)
{
}
public void mouseExited(MouseEvent arg0)
{
}
public void mousePressed(MouseEvent arg0)
{
if(arg0.getButton()==MouseEvent.BUTTON2)
{
this.drawString("你好,欢迎使用JavaApplet", 300,100);
}
}
public void mouseReleased(MouseEvent arg0)
{
}
}
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela
package Test;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class AppletMouse extends Applet implements MouseListener
{
private static final long serialVersionUID = 1L;
AppletMouse()
{
this.addMouseListener(this);
}
private void drawString(String string, int i, int j)
{
// TODO Auto-generated method stub
}
public static void main(String args[])
{
new AppletMouse();
}
public void mouseClicked(MouseEvent arg0)
{
}
public void mouseEntered(MouseEvent arg0)
{
}
public void mouseExited(MouseEvent arg0)
{
}
public void mousePressed(MouseEvent arg0)
{
if(arg0.getButton()==MouseEvent.BUTTON2)
{
this.drawString("你好,欢迎使用JavaApplet", 300,100);
}
}
public void mouseReleased(MouseEvent arg0)
{
}
}
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询