当前位置:首页 » 网页前端 » webtimer用法
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

webtimer用法

发布时间: 2023-08-03 12:43:38

⑴ 怎么用JAVA编程实现实时动态运行的模拟时钟

import java.awt.*;
import java.applet.Applet;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ClockApplet extends Applet implements Runnable //Applet支持线程
{
private Thread athread; //线程
private SimpleDateFormat sdateformat; //日期格式

public void init()
{

this.setBackground(Color.white);//背景颜色设为白色
this.athread = null;
}
public void paint(Graphics g)
{
this.sdateformat = new SimpleDateFormat("hh时mm分ss秒");
g.drawString(this.sdateformat.format(new Date()),25,131);

Calendar rightnow = Calendar.getInstance();
int second = rightnow.get(Calendar.SECOND);
int minute = rightnow.get(Calendar.MINUTE);
int hour = rightnow.get(Calendar.HOUR);

//半径
int R_H = 20,R_M = 4,R_S = 4;
//时针的坐标
//x ====(9-3)[0-6] (3-9)[6-0]
//y ====(12-6)[0-6] (6-12)[6-0]
int H_x ;
int H_y;
//x
if(hour == 0)
{
hour = 12;
}
if( hour >= 3 && hour <= 9 )
{
H_x = R_H*Math.abs(hour - 9);
}
else
{
if(hour > 9)
{
H_x = R_H*Math.abs(hour - 9);
}
else
{
H_x = R_H*Math.abs(hour+3);
}
}
//y
if( hour >= 6 && hour <= 12 )
{
H_y = R_H*Math.abs(hour - 12);
}
else
{
H_y = R_H*hour;
}

//分针的坐标
int M_x;
int M_y;

if(minute == 0)
{
minute = 60;
}
if( minute >= 15 && minute <= 45 )
{
M_x = R_M*Math.abs(minute - 45);
}
else
{
if(minute > 45)
{
M_x = R_M*Math.abs(minute - 45);
}
else
{
M_x = R_M*Math.abs(minute+15);
}
}
//y
if( minute >= 30 && minute < 60 )
{
M_y = R_M*Math.abs(minute - 60);
}
else
{
M_y = R_M*minute;
}

//秒针的坐标
int S_x;
int S_y;

if(second == 0)
{
second = 60;
}
if( second >= 15 && second <= 45 )
{
S_x = R_S*Math.abs(second - 45);
}
else
{
if(second > 45)
{
S_x = R_S*Math.abs(second - 45);
}
else
{
S_x = R_S*Math.abs(second+15);
}
}
//y
if( second >= 30 && second <= 60 )
{
S_y = R_S*Math.abs(second - 60);
}
else
{
S_y = R_S*second;
}

// g.drawString(String.valueOf(second),25,50);
// g.drawString(String.valueOf(minute),25,60);
// g.drawString(String.valueOf(hour),25,70);
// g.drawString(String.valueOf(H_x),25,80);
// g.drawString(String.valueOf(H_y),25,90);
g.drawOval(0,0,120,120);//距离相差10像素
g.setColor(Color.darkGray);
g.drawString("9",5,65);
g.drawString("3",110,65);
g.drawString("12",55,15);
g.drawString("6",55,115);

g.drawString("1",80,20);
g.drawString("2",100,40);
g.drawString("4",100,90);
g.drawString("5",80,110);

g.drawString("7",30,110);
g.drawString("8",10,90);
g.drawString("10",10,40);
g.drawString("11",30,20);

g.setColor(Color.red);
g.drawLine(60,60,H_x,H_y);//前一个点表示起点,另一个表示终点
g.setColor(Color.blue);
g.drawLine(60,60,M_x,M_y);
g.setColor(Color.yellow);
g.drawLine(60,60,S_x,S_y);

}
public void start()
{
if(athread == null)
{
athread = new Thread(this);
athread.start();
}
}
public void stop()
{
if(athread != null)
{
athread.interrupt();
athread = null;
}
}
public void run()
{
while(athread != null)
{
repaint();
try
{
athread.sleep(1000);
}
catch(InterruptedException e)
{

}
}
}

}

⑵ 怎么用C#的webBrowser模拟点击页面上的标签

C#中的WebBrowser控件的使用
0、常用方法

Navigate(string urlString):浏览urlString表示的网址
Navigate(System.Uri url):浏览url表示的网址
Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders): 浏览urlString表示的网址,并发送postData中的消息
//(通常我们登录一个网站的时候就会把用户名和密码作为postData发送出去)
GoBack():后退
GoForward():前进
Refresh():刷新
Stop():停止
GoHome():浏览主页
WebBrowser控件的常用属性:
Document:获取当前正在浏览的文档
DocumentTitle:获取当前正在浏览的网页标题
StatusText:获取当前状态栏的文本
Url:获取当前正在浏览的网址的Uri
ReadyState:获取浏览的状态
WebBrowser控件的常用事件:
DocumentTitleChanged,
CanGoBackChanged,
CanGoForwardChanged,
DocumentTitleChanged,
ProgressChanged,
ProgressChanged

1、获取非input控件的值:
webBrowser1.Document.All["控件ID"].InnerText;
或webBrowser1.Document.GetElementById("控件ID").InnerText;
或webBrowser1.Document.GetElementById("控件ID").GetAttribute("value");

2、获取input控件的值:
webBrowser1.Document.All["控件ID"].GetAttribute("value");;
或webBrowser1.Document.GetElementById("控件ID").GetAttribute("value");

3、给输入框赋值:
//输入框
user.InnerText = "myname";
password.InnerText = "123456";
webBrowser1.Document.GetElementById("password").SetAttribute("value", "Welcome123");

4、下拉、复选、多选:

//下拉框:
secret.SetAttribute("value", "question1");
//复选框
rememberme.SetAttribute("Checked", "True");
//多选框
cookietime.SetAttribute("checked", "checked");

5、根据已知有ID的元素操作没有ID的元素:
HtmlElement btnDelete = webBrowser1.Document.GetElementById(passengerId).Parent.Parent.Parent.Parent.FirstChild.FirstChild.Children[1].FirstChild.FirstChild;

根据Parent,FirstChild,Children[1]数组,多少层级的元素都能找到。

6、获取Div或其他元素的样式:
webBrowser1.Document.GetElementById("addDiv").Style;

7、直接执行页面中的脚本函数,带动态参数或不带参数都行:
Object[] objArray = new Object[1];
objArray[0] = (Object)this.labFlightNumber.Text;
webBrowser1.Document.InvokeScript("ticketbook", objArray);
webBrowser1.Document.InvokeScript("return false");

8、自动点击、自动提交:
HtmlElement btnAdd = doc.GetElementById("addDiv").FirstChild;
btnAdd.InvokeMember("Click");

9、自动赋值,然后点击提交按钮的时候如果出现脚本错误或一直加载的问题,一般都是点击事件执行过快,这时需要借助Timer控件延迟执行提交按钮事件:

this.timer1.Enabled = true;
this.timer1.Interval = 1000 * 2;
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
ClickBtn.InvokeMember("Click");//执行按扭操作
}

10、屏蔽脚本错误:
将WebBrowser控件ScriptErrorsSuppressed设置为True即可

11、自动点击弹出提示框:

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
//自动点击弹出确认或弹出提示
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); //弹出确认
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");//弹出提示
}

WebBrowser页面加载完毕之后,在页面中进行一些自动化操作的时候弹出框的自动点击(屏蔽)

private void webBrowser1_DocumentCompleted(object sender, e)
{
//自动点击弹出确认或弹出提示
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); //弹出确认
vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");//弹出提示
//下面是你的执行操作代码
}

12、获取网页中的Iframe,并设置Iframe的src
HtmlDocument docFrame = webBrowser1.Document.Window.Frames["mainFrame"].Document;

HtmlDocument docFrame = webBrowser1.Document.All.Frames["mainFrame"].Document;
docFrame.All["mainFrame"].SetAttribute("src", "http://www..com/");

13、网页中存在Iframe的时候webBrowser1.Url和webBrowser1_DocumentCompleted中的e.Url不一样,前者是主框架的Url,后者是当前活动框口的Url。

14、让控件聚焦
this.webBrowser1.Select();
this.webBrowser1.Focus();
doc.All["TPL_password_1"].Focus();

15、打开本地网页文件
webBrowser1.Navigate(Application.StartupPath + @"\Test.html");

16、获取元素、表单

//根据Name获取元素
public HtmlElement GetElement_Name(WebBrowser wb,string Name)
{
HtmlElement e = wb.Document.All[Name];
return e;
}

//根据Id获取元素
public HtmlElement GetElement_Id(WebBrowser wb, string id)
{
HtmlElement e = wb.Document.GetElementById(id);
return e;
}

//根据Index获取元素
public HtmlElement GetElement_Index(WebBrowser wb,int index)
{
HtmlElement e = wb.Document.All[index];
return e;
}

//获取form表单名name,返回表单
public HtmlElement GetElement_Form(WebBrowser wb,string form_name)
{
HtmlElement e = wb.Document.Forms[form_name];
return e;
}

//设置元素value属性的值
public void Write_value(HtmlElement e,string value)
{
e.SetAttribute("value", value);
}

//执行元素的方法,如:click,submit(需Form表单名)等
public void Btn_click(HtmlElement e,string s)
{

e.InvokeMember(s);
}