用java寫(xiě)的話(huà) 要做得很好 已經(jīng)來(lái)不及了
成都創(chuàng)新互聯(lián)主營(yíng)平武網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app軟件開(kāi)發(fā),平武h5重慶小程序開(kāi)發(fā)公司搭建,平武網(wǎng)站營(yíng)銷(xiāo)推廣歡迎平武等地區(qū)企業(yè)咨詢(xún)
我建議你用ZineMaker 2006做一個(gè)雜志 可以做得很漂亮 可以加她照片、背景音樂(lè)加特殊效果等等 她看見(jiàn)了肯定會(huì)感動(dòng)的
這里一個(gè)常見(jiàn)的 也給你
html
head
title一切皆有可能/title!--這里是標(biāo)題--
hta:application sysmenu=no scroll=no border=none
script language="vc"
sub sub1
me.close
end sub
me.resizeto 500,410 '這里設(shè)置窗口大小,單位為像素
me.moveto 260,100 '這里設(shè)置窗口位置,單位為像素
window.settimeout "sub1",100000 '這是設(shè)置時(shí)間,單位為毫秒,我這里設(shè)置為12秒
/script
body
CENTER
FONT style="COLOR:#33FF00; FILTER: shadow(color=black); FONT-FAMILY: 華文彩云; FONT-SIZE: 30pt; LINE-HEIGHT: 150%; WIDTH: 100%"B一切皆有可能/B/FONT/CENTER
hr
style type="text/css"
.3dfont { FILTER: glow(color=ffffff,strength=0) shadow(color=cccccc,direction:135); POSITION: relative; WIDTH: 100% }
/style
table border="0" width="100%"
tr
td width="100%" class="3dfont"font color=REDCENTER ☆☆☆☆☆☆ 獻(xiàn)給最親愛(ài)的你 ☆☆☆☆☆☆/font
br
P align=left
★一切皆有可能!/Bbrbr
一切皆有可能!/Bbrbr
MARQUEE希望大家多多支持?。?!/body
/html
【ClientSocketDemo.java 客戶(hù)端Java源代碼】
import java.net.*;
import java.io.*;
public class ClientSocketDemo
{
//聲明客戶(hù)端Socket對(duì)象socket
Socket socket = null;
//聲明客戶(hù)器端數(shù)據(jù)輸入輸出流
DataInputStream in;
DataOutputStream out;
//聲明字符串?dāng)?shù)組對(duì)象response,用于存儲(chǔ)從服務(wù)器接收到的信息
String response[];
//執(zhí)行過(guò)程中,沒(méi)有參數(shù)時(shí)的構(gòu)造方法,本地服務(wù)器在本地,取默認(rèn)端口10745
public ClientSocketDemo()
{
try
{
//創(chuàng)建客戶(hù)端socket,服務(wù)器地址取本地,端口號(hào)為10745
socket = new Socket("localhost",10745);
//創(chuàng)建客戶(hù)端數(shù)據(jù)輸入輸出流,用于對(duì)服務(wù)器端發(fā)送或接收數(shù)據(jù)
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
//獲取客戶(hù)端地址及端口號(hào)
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
//向服務(wù)器發(fā)送數(shù)據(jù)
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
//從服務(wù)器接收數(shù)據(jù)
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
//執(zhí)行過(guò)程中,有一個(gè)參數(shù)時(shí)的構(gòu)造方法,參數(shù)指定服務(wù)器地址,取默認(rèn)端口10745
public ClientSocketDemo(String hostname)
{
try
{
//創(chuàng)建客戶(hù)端socket,hostname參數(shù)指定服務(wù)器地址,端口號(hào)為10745
socket = new Socket(hostname,10745);
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
//執(zhí)行過(guò)程中,有兩個(gè)個(gè)參數(shù)時(shí)的構(gòu)造方法,第一個(gè)參數(shù)hostname指定服務(wù)器地址
//第一個(gè)參數(shù)serverPort指定服務(wù)器端口號(hào)
public ClientSocketDemo(String hostname,String serverPort)
{
try
{
socket = new Socket(hostname,Integer.parseInt(serverPort));
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);
response = new String[3];
for (int i = 0; i response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}
public static void main(String[] args)
{
String comd[] = args;
if(comd.length == 0)
{
System.out.println("Use localhost(127.0.0.1) and default port");
ClientSocketDemo demo = new ClientSocketDemo();
}
else if(comd.length == 1)
{
System.out.println("Use default port");
ClientSocketDemo demo = new ClientSocketDemo(args[0]);
}
else if(comd.length == 2)
{
System.out.println("Hostname and port are named by user");
ClientSocketDemo demo = new ClientSocketDemo(args[0],args[1]);
}
else System.out.println("ERROR");
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
【ServerSocketDemo.java 服務(wù)器端Java源代碼】
import java.net.*;
import java.io.*;
public class ServerSocketDemo
{
//聲明ServerSocket類(lèi)對(duì)象
ServerSocket serverSocket;
//聲明并初始化服務(wù)器端監(jiān)聽(tīng)端口號(hào)常量
public static final int PORT = 10745;
//聲明服務(wù)器端數(shù)據(jù)輸入輸出流
DataInputStream in;
DataOutputStream out;
//聲明InetAddress類(lèi)對(duì)象ip,用于獲取服務(wù)器地址及端口號(hào)等信息
InetAddress ip = null;
//聲明字符串?dāng)?shù)組對(duì)象request,用于存儲(chǔ)從客戶(hù)端發(fā)送來(lái)的信息
String request[];
public ServerSocketDemo()
{
request = new String[3]; //初始化字符串?dāng)?shù)組
try
{
//獲取本地服務(wù)器地址信息
ip = InetAddress.getLocalHost();
//以PORT為服務(wù)端口號(hào),創(chuàng)建serverSocket對(duì)象以監(jiān)聽(tīng)該端口上的連接
serverSocket = new ServerSocket(PORT);
//創(chuàng)建Socket類(lèi)的對(duì)象socket,用于保存連接到服務(wù)器的客戶(hù)端socket對(duì)象
Socket socket = serverSocket.accept();
System.out.println("This is server:"+String.valueOf(ip)+PORT);
//創(chuàng)建服務(wù)器端數(shù)據(jù)輸入輸出流,用于對(duì)客戶(hù)端接收或發(fā)送數(shù)據(jù)
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
//接收客戶(hù)端發(fā)送來(lái)的數(shù)據(jù)信息,并顯示
request[0] = in.readUTF();
request[1] = in.readUTF();
request[2] = in.readUTF();
System.out.println("Received messages form client is:");
System.out.println(request[0]);
System.out.println(request[1]);
System.out.println(request[2]);
//向客戶(hù)端發(fā)送數(shù)據(jù)
out.writeUTF("Hello client!");
out.writeUTF("Your ip is:"+request[1]);
out.writeUTF("Your port is:"+request[2]);
}
catch(IOException e){e.printStackTrace();}
}
public static void main(String[] args)
{
ServerSocketDemo demo = new ServerSocketDemo();
}
}
連連看java源代碼
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戲按鈕數(shù)組
JButton exitButton,resetButton,newlyButton; //退出,重列,重新開(kāi)始按鈕
JLabel fractionLable=new JLabel("0"); //分?jǐn)?shù)標(biāo)簽
JButton firstButton,secondButton; //分別記錄兩次被選中的按鈕
int grid[][] = new int[8][7];//儲(chǔ)存游戲按鈕位置
static boolean pressInformation=false; //判斷是否有按鈕被選中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標(biāo)
int i,j,k,n;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ連連看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols 6;cols++){
for(int rows = 0;rows 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再來(lái)一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins=15;twins++) {
randoms=(int)(Math.random()*25+1);
for(int alike=1;alike=2;alike++) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i=6;i++) {
for(int j=0;j=5;j++) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n++;
}
}
}
n=n-1;
this.grid=grid;
while(n=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //這里一定要將按鈕點(diǎn)擊信息歸為初始
init();
for(int i = 0;i 6;i++){
for(int j = 0;j 5;j++ ){
if(grid[i+1][j+1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsg secondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情況下能不能消去。仔細(xì)分析,不一條條注釋
if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判斷是否相鄰
remove();
}
else{
for (j=0;j7;j++ ) {
if (grid[x0][j]==0){ //判斷第一個(gè)按鈕同行哪個(gè)按鈕為空
if (yj) { //如果第二個(gè)按鈕的Y坐標(biāo)大于空按鈕的Y坐標(biāo)說(shuō)明第一按鈕在第二按鈕左邊
for (i=y-1;i=j;i-- ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒(méi)有按鈕
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1說(shuō)明通過(guò)了第一次驗(yàn)證
}
if (k==1) {
linePassOne();
}
}
if (yj){ //如果第二個(gè)按鈕的Y坐標(biāo)小于空按鈕的Y坐標(biāo)說(shuō)明第一按鈕在第二按鈕右邊
for (i=y+1;i=j ;i++ ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒(méi)有按鈕
if (grid[x][i]!=0){
k=0;
break;
}
else { k=1; }
}
if (k==1){
linePassOne();
}
}
if (y==j ) {
linePassOne();
}
}
if (k==2) {
if (x0==x) {
remove();
}
if (x0x) {
for (n=x0;n=x-1;n++ ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 n==x-1) {
remove();
}
}
}
if (x0x) {
for (n=x0;n=x+1 ;n-- ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 n==x+1) {
remove();
}
}
}
}
}
for (i=0;i8;i++ ) { //列
if (grid[i][y0]==0) {
if (xi) {
for (j=x-1;j=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
for (j=x+1;j=i;j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x==i) {
rowPassOne();
}
}
if (k==2){
if (y0==y) {
remove();
}
if (y0y) {
for (n=y0;n=y-1 ;n++ ) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 n==y-1) {
remove();
}
}
}
if (y0y) {
for (n=y0;n=y+1 ;n--) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 n==y+1) {
remove();
}
}
}
}
}
}
}
public void linePassOne(){
if (y0j){ //第一按鈕同行空按鈕在左邊
for (i=y0-1;i=j ;i-- ){ //判斷第一按鈕同左側(cè)空按鈕之間有沒(méi)按鈕
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2說(shuō)明通過(guò)了第二次驗(yàn)證
}
}
if (y0j){ //第一按鈕同行空按鈕在與第二按鈕之間
for (i=y0+1;i=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1;j=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0i) {
for (j=x0+1;j=i ;j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
public void remove(){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==newlyButton){
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation=false;
init();
}
if(e.getSource()==exitButton)
System.exit(0);
if(e.getSource()==resetButton)
reload();
for(int cols = 0;cols 6;cols++){
for(int rows = 0;rows 5;rows++ ){
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
lianliankan llk = new lianliankan();
llk.randomBuild();
llk.init();
}
}
//old 998 lines
//new 318 lines
基于JAVA的3D坦克游戲源代碼
JAVA猜數(shù)字小游戲源代碼
/*1、編寫(xiě)一個(gè)猜數(shù)字的游戲,由電腦隨機(jī)產(chǎn)生一個(gè)100以?xún)?nèi)的整數(shù),讓用戶(hù)去猜,如果用戶(hù)猜的比電腦大,則輸出“大了,再小點(diǎn)!”,反之則輸出“小了,再大點(diǎn)!”,用戶(hù)總共只能猜十次,并根據(jù)用戶(hù)正確猜出答案所用的次數(shù)輸出相應(yīng)的信息,如:只用一次就猜對(duì),輸出“你是個(gè)天才!”,八次才猜對(duì),輸出“笨死了!”,如果十次還沒(méi)有猜對(duì),則游戲結(jié)束!*/
import java.util.*;
import java.io.*;
public class CaiShu{
public static void main(String[] args) throws IOException{
Random a=new Random();
int num=a.nextInt(100);
System.out.println("請(qǐng)輸入一個(gè)100以?xún)?nèi)的整數(shù):");
for (int i=0;i=9;i++){
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String str=bf.readLine();
int shu=Integer.parseInt(str);
if (shunum)
System.out.println("輸入的數(shù)大了,輸小點(diǎn)的!");
else if (shunum)
System.out.println("輸入的數(shù)小了,輸大點(diǎn)的!");
else {
System.out.println("恭喜你,猜對(duì)了!");
if (i=2)
System.out.println("你真是個(gè)天才!");
else if (i=6)
System.out.println("還將就,你過(guò)關(guān)了!");
else if (i=8)
System.out.println("但是你還……真笨!");
else
System.out.println("你和豬沒(méi)有兩樣了!");
break;}
}
}
}
表1. CheckerDrag.java
// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{ // Dimension of checkerboard square. // 棋盤(pán)上每個(gè)小方格的尺寸 final static int SQUAREDIM = 40; // Dimension of checkerboard -- includes black outline. // 棋盤(pán)的尺寸 – 包括黑色的輪廓線(xiàn) 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)用戶(hù)在棋子上按下鼠標(biāo)按鍵時(shí)設(shè)為true, // 釋放鼠標(biāo)按鍵時(shí)設(shè)為false boolean inDrag = false; // Left coordinate of checkerboard's upper-left corner. // 棋盤(pán)左上角的左方向坐標(biāo) int boardx; // Top coordinate of checkerboard's upper-left corner. //棋盤(pán)左上角的上方向坐標(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. // 初始化棋盤(pán)的原點(diǎn),使棋盤(pá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)聽(tīng)鼠標(biāo)按鍵的按下和釋放事件的鼠標(biāo)監(jiān)聽(tīng)器 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)聽(tīng)鼠標(biāo)拖動(dòng)事件的鼠標(biāo)運(yùn)動(dòng)監(jiān)聽(tīng)器 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). // 如果棋子(至少是棋子的一部分)沒(méi)有被 // 移出棋盤(pán),則將之前計(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)的位置上繪制棋盤(pán) 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. // 繪制棋盤(pán)輪廓線(xiàn) g.setColor (Color.black); g.drawRect (x, y, 8 * SQUAREDIM + 1, 8 * SQUAREDIM + 1); // Paint checkerboard. // 繪制棋盤(pán) 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類(lèi)繼承的默認(rèn)實(shí)現(xiàn)會(huì)在調(diào)用paint()之前,將applet的繪圖區(qū)域清除 // 為背景色,這種繪制之后的清除就導(dǎo)致了閃爍。CheckerDrag重寫(xiě)了update()來(lái) // 防止背景被清除,從而消除了閃爍。 public void update (Graphics g) { paint (g); }}
package com.test01;
import java.util.Scanner;
public class oop5 { public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// int x = 9;
// int y = 1;
int x = sc.nextInt();
int y = sc.nextInt();
int z;
z = add(x, y);
System.out.println("x的值為:" + x);
System.out.println("y的值為:" + y);
System.out.println("二者之和為:" + z);
}
/** 四種小算法 */
// 加法運(yùn)算
public static int add(int a, int b) {
int c;
c = a + b;
return c;
}
// 減法運(yùn)算
public static int jian(int d, int v) {
int m;
m = d - v;
return m;
}
// 乘積運(yùn)算
public static int addAdd(int q, int w) {
int e;
e = q * w;
return e;
}
// 除法運(yùn)算
public static int chu(int p, int k) {
int f;
f = p / k;
return f;
}
}
利用MFC畫(huà)出一個(gè)大的心型, 再在里面畫(huà)兩個(gè)小人,一個(gè)男(你),一個(gè)女(她)。 定時(shí)讓把里面的小人跑起來(lái)、或者跳舞。(利用重繪機(jī)制) 然后,還可以在心里面的某個(gè)位置寫(xiě)上一句祝福的話(huà)。 這東西似乎有點(diǎn)難度啊。 不過(guò),祝你幸福呀。