這是js...
創(chuàng)新互聯(lián)公司專注于二七網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供二七營(yíng)銷型網(wǎng)站建設(shè),二七網(wǎng)站制作、二七網(wǎng)頁(yè)設(shè)計(jì)、二七網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造二七網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供二七網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
dom的話設(shè)置div的top和bottom屬性,用setTimeout()或者setInterval()方法
jquery的話就簡(jiǎn)單了,直接用animate()方法,也是設(shè)置top和bottom屬性,slideUp()和slideDown()方法也行。
看注釋:
import java.awt.GridLayout;
import javax.swing.*;
public class LoadForm extends JFrame{
private JPanel jpanel1;
private JTextField jtext1;
private JPasswordField password;
private JLabel jlable1;
private JLabel jlable2;
private JButton button1;
private JButton button2;
public LoadForm()
{
super("商品管理系統(tǒng)");
this.setLayout(null);
GridLayout layout=new GridLayout(3,3,10,10);//這句保留
jpanel1=new JPanel();
//jpanel1.setLayout(null);//jpanel1的布局不能為空
jlable1=new JLabel("用戶名");
jlable2=new JLabel("密 碼");
jtext1=new JTextField();
password=new JPasswordField();
button1=new JButton("確定");
button2=new JButton("取消");
jpanel1.add(jlable1);
jpanel1.add(jtext1);
jpanel1.add(jlable2);
jpanel1.add(password);
jpanel1.add(button1);
jpanel1.add(button2);
//this.add(jpanel1);//寫法錯(cuò)誤
this.setContentPane(jpanel1);//設(shè)置jpanel1為Frame的內(nèi)容面版
this.setBounds(200,200,100,100);
//this.setSize(200,200);
this.setVisible(true);
}
//main方法測(cè)試
public static void main(String args[]){
new LoadForm();
}
}
你可以使用以下代碼代替你的 ACTION_CALL(推薦):
Intent?intent?=?new?Intent(Intent.ACTION_DIAL);
也可以參考這里,在 manifest?中添加
android.permission.PHONE_CALL
的權(quán)限,并且在撥打電話之前檢驗(yàn)權(quán)限:
//檢查是否已經(jīng)給了權(quán)限
int?checkpermission=?ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.ACCESS_FINE_LOCATION);
if(checkpermission!=PackageManager.PERMISSION_GRANTED){?//沒有給權(quán)限,申請(qǐng)
//參數(shù)分別是當(dāng)前活動(dòng),權(quán)限字符串?dāng)?shù)組,requestcode
ActivityCompat.requestPermissions(MainActivity.this,new?String[]{Manifest.permission.ACCESS_FINE_LOCATION},?1);
//?暫時(shí)使用?DIAL?代替?CALL
Intent?intent?=?new?Intent(Intent.PHONE_DIAL);
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);
}?else?{
//?直接使用?CALL
Intent?intent?=?new?Intent(Intent.PHONE_CALL);
intent.setData(Uri.parse("tel:"+number));
startActivity(intent);
}
然后添加一個(gè)方法:
@Override
public?void?onRequestPermissionsResult(int?requestCode,?@NonNull?String[]?permissions,?@NonNull?int[]?grantResults)?{
super.onRequestPermissionsResult(requestCode,?permissions,?grantResults);
//grantResults數(shù)組與權(quán)限字符串?dāng)?shù)組對(duì)應(yīng),里面存放權(quán)限申請(qǐng)結(jié)果
if(grantResults[0]==?PackageManager.PERMISSION_GRANTED){
//?放已授權(quán)的處理方法
}else{
//?放拒絕授權(quán)的處理方法
Toast.makeText(MainActivity.this,"拒絕授權(quán)",Toast.LENGTH_SHORT).show();
}
}
參考:CSDN
這是代碼,你可以自己調(diào)試一下。
數(shù)據(jù)結(jié)構(gòu)如下:
CREATE TABLE dtree (
id int,
pid int,
name varchar(200),
url varchar(200),
title varchar(200),
target varchar(200),
icon varchar(200),
iconopen varchar(200),
opened bit);
為了實(shí)現(xiàn)獲取數(shù)據(jù)庫(kù)變量功能,需要建立一個(gè)DTree類,并編譯生成CLASS文件,放入\WEB-INF\classes文件夾下。
DTree類代碼如下:
package work3;
public class DTree {
private int id;
private int pid;
private String name;
private String url;
private String title;
private String target;
private String icon;
private String iconOpen;
private int opened;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getIconOpen() {
return iconOpen;
}
public void setIconOpen(String iconOpen) {
this.iconOpen = iconOpen;
}
public int getOpened() {
return opened;
}
public void setOpened(int opened) {
this.opened = opened;
}
}
work3.jsp代碼如下:
%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%
%@ page import="java.sql.*"%
jsp:useBean id='settree' scope="application" class="work3.DTree" /
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
""
html
head
meta http-equiv="Content-Type" content="text/html; charset=GB18030"
link rel="StyleSheet" href="dtree.css" type="text/css" /
script type="text/javascript" src="dtree.js"/script
titledTree in MySQL/title
/head
body
h2
Example
/h2
div class="dtree"
p
a href="javascript: d.openAll();"open all/a |
a href="javascript: d.closeAll();"close all/a
/p
script type="text/javascript"
!--
d = new dTree('d');
%
//驅(qū)動(dòng)程序名
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
//數(shù)據(jù)庫(kù)用戶名
String userName = "sa";
//密碼
String userPwd = "1";
//數(shù)據(jù)庫(kù)名
String dbName = "master";
//表名
String tableName = "dtree";
//連接字符串
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+dbName;
//加載驅(qū)動(dòng)
Class.forName(driverName).newInstance();
//連接數(shù)據(jù)庫(kù)
java.sql.Connection conn = DriverManager.getConnection(url,userName,userPwd);
//得到Statement實(shí)例
java.sql.Statement statement = conn.createStatement();
//查詢數(shù)據(jù)
String sql = "select * from " + tableName;
//返回結(jié)果
java.sql.ResultSet rs = statement.executeQuery(sql);
//獲取變量
while (rs.next()) {
settree.setId(rs.getInt(1));
settree.setPid(rs.getInt(2));
settree.setName(rs.getString(3));
settree.setUrl(rs.getString(4));
settree.setTitle(rs.getString(5));
settree.setTarget(rs.getString(6));
settree.setIcon(rs.getString(7));
settree.setIconOpen(rs.getString(8));
settree.setOpened(rs.getInt(9));
if(settree.getPid()==0)
settree.setOpened(1);
%
d.add(%=settree.getId()%,%=settree.getPid()%,'%=settree.getName()%','%=settree.getUrl()%','%=settree.getTitle()%','%=settree.getTarget()%','','',%=settree.getOpened()%);
%
}
%
document.write(d);
//--
/script
/div
/body
/html
表1. CheckerDrag.java
// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{ // Dimension of checkerboard square. // 棋盤上每個(gè)小方格的尺寸 final static int SQUAREDIM = 40; // Dimension of checkerboard -- includes black outline. // 棋盤的尺寸 – 包括黑色的輪廓線 final static int BOARDDIM = 8 * SQUAREDIM + 2; // Dimension of checker -- 3/4 the dimension of a square. // 棋子的尺寸 – 方格尺寸的3/4 final static int CHECKERDIM = 3 * SQUAREDIM / 4; // Square colors are dark green or white. // 方格的顏色為深綠色或者白色 final static Color darkGreen = new Color (0, 128, 0); // Dragging flag -- set to true when user presses mouse button over checker // and cleared to false when user releases mouse button. // 拖動(dòng)標(biāo)記 --當(dāng)用戶在棋子上按下鼠標(biāo)按鍵時(shí)設(shè)為true, // 釋放鼠標(biāo)按鍵時(shí)設(shè)為false boolean inDrag = false; // Left coordinate of checkerboard's upper-left corner. // 棋盤左上角的左方向坐標(biāo) int boardx; // Top coordinate of checkerboard's upper-left corner. //棋盤左上角的上方向坐標(biāo) int boardy; // Left coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原點(diǎn)(左上角)的左方向坐標(biāo) int ox; // Top coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原點(diǎn)(左上角)的上方向坐標(biāo) int oy; // Left displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按鍵時(shí)的鼠標(biāo)坐標(biāo)與棋子矩形原點(diǎn)之間的左方向位移 int relx; // Top displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按鍵時(shí)的鼠標(biāo)坐標(biāo)與棋子矩形原點(diǎn)之間的上方向位移 int rely; // Width of applet drawing area. // applet繪圖區(qū)域的寬度 int width; // Height of applet drawing area. // applet繪圖區(qū)域的高度 int height; // Image buffer. // 圖像緩沖 Image imBuffer; // Graphics context associated with image buffer. // 圖像緩沖相關(guān)聯(lián)的圖形背景 Graphics imG; public void init () { // Obtain the size of the applet's drawing area. // 獲取applet繪圖區(qū)域的尺寸 width = getSize ().width; height = getSize ().height; // Create image buffer. // 創(chuàng)建圖像緩沖 imBuffer = createImage (width, height); // Retrieve graphics context associated with image buffer. // 取出圖像緩沖相關(guān)聯(lián)的圖形背景 imG = imBuffer.getGraphics (); // Initialize checkerboard's origin, so that board is centered. // 初始化棋盤的原點(diǎn),使棋盤在屏幕上居中 boardx = (width - BOARDDIM) / 2 + 1; boardy = (height - BOARDDIM) / 2 + 1; // Initialize checker's rectangle's starting origin so that checker is // centered in the square located in the top row and second column from // the left. // 初始化棋子矩形的起始原點(diǎn),使得棋子在第一行左數(shù)第二列的方格里居中 ox = boardx + SQUAREDIM + (SQUAREDIM - CHECKERDIM) / 2 + 1; oy = boardy + (SQUAREDIM - CHECKERDIM) / 2 + 1; // Attach a mouse listener to the applet. That listener listens for // mouse-button press and mouse-button release events. // 向applet添加一個(gè)用來(lái)監(jiān)聽鼠標(biāo)按鍵的按下和釋放事件的鼠標(biāo)監(jiān)聽器 addMouseListener (new MouseAdapter () { public void mousePressed (MouseEvent e) { // Obtain mouse coordinates at time of press. // 獲取按鍵時(shí)的鼠標(biāo)坐標(biāo) int x = e.getX (); int y = e.getY (); // If mouse is over draggable checker at time // of press (i.e., contains (x, y) returns // true), save distance between current mouse // coordinates and draggable checker origin // (which will always be positive) and set drag // flag to true (to indicate drag in progress). // 在按鍵時(shí)如果鼠標(biāo)位于可拖動(dòng)的棋子上方 // (也就是contains (x, y)返回true),則保存當(dāng)前 // 鼠標(biāo)坐標(biāo)與棋子的原點(diǎn)之間的距離(始終為正值)并且 // 將拖動(dòng)標(biāo)志設(shè)為true(用來(lái)表明正處在拖動(dòng)過(guò)程中) if (contains (x, y)) { relx = x - ox; rely = y - oy; inDrag = true; } } boolean contains (int x, int y) { // Calculate center of draggable checker. // 計(jì)算棋子的中心位置 int cox = ox + CHECKERDIM / 2; int coy = oy + CHECKERDIM / 2; // Return true if (x, y) locates with bounds // of draggable checker. CHECKERDIM / 2 is the // radius. // 如果(x, y)仍處于棋子范圍內(nèi)則返回true // CHECKERDIM / 2為半徑 return (cox - x) * (cox - x) + (coy - y) * (coy - y) CHECKERDIM / 2 * CHECKERDIM / 2; } public void mouseReleased (MouseEvent e) { // When mouse is released, clear inDrag (to // indicate no drag in progress) if inDrag is // already set. // 當(dāng)鼠標(biāo)按鍵被釋放時(shí),如果inDrag已經(jīng)為true, // 則將其置為false(用來(lái)表明不在拖動(dòng)過(guò)程中) if (inDrag) inDrag = false; } }); // Attach a mouse motion listener to the applet. That listener listens // for mouse drag events. //向applet添加一個(gè)用來(lái)監(jiān)聽鼠標(biāo)拖動(dòng)事件的鼠標(biāo)運(yùn)動(dòng)監(jiān)聽器 addMouseMotionListener (new MouseMotionAdapter () { public void mouseDragged (MouseEvent e) { if (inDrag) { // Calculate draggable checker's new // origin (the upper-left corner of // the checker rectangle). // 計(jì)算棋子新的原點(diǎn)(棋子矩形的左上角) int tmpox = e.getX () - relx; int tmpoy = e.getY () - rely; // If the checker is not being moved // (at least partly) off board, // assign the previously calculated // origin (tmpox, tmpoy) as the // permanent origin (ox, oy), and // redraw the display area (with the // draggable checker at the new // coordinates). // 如果棋子(至少是棋子的一部分)沒有被 // 移出棋盤,則將之前計(jì)算的原點(diǎn) // (tmpox, tmpoy)賦值給永久性的原點(diǎn)(ox, oy), // 并且刷新顯示區(qū)域(此時(shí)的棋子已經(jīng)位于新坐標(biāo)上) if (tmpox boardx tmpoy boardy tmpox + CHECKERDIM boardx + BOARDDIM tmpoy + CHECKERDIM boardy + BOARDDIM) { ox = tmpox; oy = tmpoy; repaint (); } } } }); } public void paint (Graphics g) { // Paint the checkerboard over which the checker will be dragged. // 在棋子將要被拖動(dòng)的位置上繪制棋盤 paintCheckerBoard (imG, boardx, boardy); // Paint the checker that will be dragged. // 繪制即將被拖動(dòng)的棋子 paintChecker (imG, ox, oy); // Draw contents of image buffer. // 繪制圖像緩沖的內(nèi)容 g.drawImage (imBuffer, 0, 0, this); } void paintChecker (Graphics g, int x, int y) { // Set checker shadow color. // 設(shè)置棋子陰影的顏色 g.setColor (Color.black); // Paint checker shadow. // 繪制棋子的陰影 g.fillOval (x, y, CHECKERDIM, CHECKERDIM); // Set checker color. // 設(shè)置棋子顏色 g.setColor (Color.red); // Paint checker. // 繪制棋子 g.fillOval (x, y, CHECKERDIM - CHECKERDIM / 13, CHECKERDIM - CHECKERDIM / 13); } void paintCheckerBoard (Graphics g, int x, int y) { // Paint checkerboard outline. // 繪制棋盤輪廓線 g.setColor (Color.black); g.drawRect (x, y, 8 * SQUAREDIM + 1, 8 * SQUAREDIM + 1); // Paint checkerboard. // 繪制棋盤 for (int row = 0; row 8; row++) { g.setColor (((row 1) != 0) ? darkGreen : Color.white); for (int col = 0; col 8; col++) { g.fillRect (x + 1 + col * SQUAREDIM, y + 1 + row * SQUAREDIM, SQUAREDIM, SQUAREDIM); g.setColor ((g.getColor () == darkGreen) ? Color.white : darkGreen); } } } // The AWT invokes the update() method in response to the repaint() method // calls that are made as a checker is dragged. The default implementation // of this method, which is inherited from the Container class, clears the // applet's drawing area to the background color prior to calling paint(). // This clearing followed by drawing causes flicker. CheckerDrag overrides // update() to prevent the background from being cleared, which eliminates // the flicker. // AWT調(diào)用了update()方法來(lái)響應(yīng)拖動(dòng)棋子時(shí)所調(diào)用的repaint()方法。該方法從 // Container類繼承的默認(rèn)實(shí)現(xiàn)會(huì)在調(diào)用paint()之前,將applet的繪圖區(qū)域清除 // 為背景色,這種繪制之后的清除就導(dǎo)致了閃爍。CheckerDrag重寫了update()來(lái) // 防止背景被清除,從而消除了閃爍。 public void update (Graphics g) { paint (g); }}
Java編程的特點(diǎn)是什么呢?
Java由美國(guó)SUN公司(被oracle公司收購(gòu))發(fā)明于1995年,是目前業(yè)界應(yīng)用最廣泛、使用人數(shù)最多的語(yǔ)言,連續(xù)多年排名世界第一,可以稱之為“計(jì)算機(jī)語(yǔ)言界的英語(yǔ)”。
那么Java這么高的評(píng)價(jià)它的特點(diǎn)有哪些,下面我來(lái)為題主解答:
一、跨平臺(tái)/可移植性
這是Java的核心優(yōu)勢(shì)。Java在設(shè)計(jì)時(shí)就很注重移植和跨平臺(tái)性。比如:Java的int永遠(yuǎn)都是32位。不像C++可能是16,32,可能是根據(jù)編譯器廠商規(guī)定的變化。這樣的話程序的移植就會(huì)非常麻煩。
Java首先利用文本編輯器編寫 Java源程序,源文件的后綴名為.java;再利用編譯器(javac)將源程序編譯成字節(jié)碼文件,字節(jié)碼文件的后綴名為.class; 最后利用虛擬機(jī)(解釋器,java)解釋執(zhí)行。如下圖所示:
二、安全性
Java適合于網(wǎng)絡(luò)/分布式環(huán)境,為了達(dá)到這個(gè)目標(biāo),在安全性方面投入了很大的精力,使Java可以很容易構(gòu)建防病毒,防篡改的系統(tǒng)。比如Java取消了強(qiáng)大但又危險(xiǎn)的指針。由于指針可進(jìn)行移動(dòng)運(yùn)算,指針可隨便指向一個(gè)內(nèi)存區(qū)域,而不管這個(gè)區(qū)域是否可用,這樣做是危險(xiǎn)的。
三、面向?qū)ο?/p>
面向?qū)ο笫且环N程序設(shè)計(jì)技術(shù),非常適合大型軟件的設(shè)計(jì)和開發(fā)。由于C++為了照顧大量C語(yǔ)言使用者而兼容了C,使得自身僅僅成為了帶類的C語(yǔ)言,多少影響了其面向?qū)ο蟮膹氐仔?!Java則是完全的面向?qū)ο笳Z(yǔ)言。
四、簡(jiǎn)單性
Java就是C++語(yǔ)法的簡(jiǎn)化版,我們也可以將Java稱之為“C++-”。跟我念“C加加減”,指的就是將C++的一些內(nèi)容去掉;比如:頭文件,指針運(yùn)算,結(jié)構(gòu),聯(lián)合,操作符重載,虛基類等等。同時(shí),由于語(yǔ)法基于C語(yǔ)言,因此學(xué)習(xí)起來(lái)完全不費(fèi)力。
五、高性能
Java最初發(fā)展階段,總是被人詬病“性能低”;客觀上,高級(jí)語(yǔ)言運(yùn)行效率總是低于低級(jí)語(yǔ)言的,這個(gè)無(wú)法避免。Java語(yǔ)言本身發(fā)展中通過(guò)虛擬機(jī)的優(yōu)化提升了幾十倍運(yùn)行效率。比如,通過(guò)JIT(JUST IN TIME)即時(shí)編譯技術(shù)提高運(yùn)行效率。 將一些“熱點(diǎn)”字節(jié)碼編譯成本地機(jī)器碼,并將結(jié)果緩存起來(lái),在需要的時(shí)候重新調(diào)用。這樣的話,使Java程序的執(zhí)行效率大大提高,某些代碼甚至接近C++的效率。
因此,Java低性能的短腿,已經(jīng)被完全解決了。業(yè)界發(fā)展上,我們也看到很多C++應(yīng)用轉(zhuǎn)到Java開發(fā),很多C++程序員轉(zhuǎn)型為Java程序員。
六、分布式
Java是為Internet的分布式環(huán)境設(shè)計(jì)的,因?yàn)樗軌蛱幚鞹CP/IP協(xié)議。事實(shí)上,通過(guò)URL訪問一個(gè)網(wǎng)絡(luò)資源和訪問本地文件是一樣簡(jiǎn)單的。Java還支持遠(yuǎn)程方法調(diào)用(RMI,Remote Method Invocation),使程序能夠通過(guò)網(wǎng)絡(luò)調(diào)用方法。
七、多線程
多線程的使用可以帶來(lái)更好的交互響應(yīng)和實(shí)時(shí)行為。 Java多線程的簡(jiǎn)單性是Java成為主流服務(wù)器端開發(fā)語(yǔ)言的主要原因之一。
八、健壯性
Java是一種健壯的語(yǔ)言,吸收了C/C++ 語(yǔ)言的優(yōu)點(diǎn),但去掉了其影響程序健壯性的部分(如:指針、內(nèi)存的申請(qǐng)與釋放等)。Java程序不可能造成計(jì)算機(jī)崩潰。即使Java程序也可能有錯(cuò)誤。如果出現(xiàn)某種出乎意料之事,程序也不會(huì)崩潰,而是把該異常拋出,再通過(guò)異常處理機(jī)制加以處理。
以上幾種特性你了解到啦嗎?? ? 記得給個(gè)贊!