RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java贺卡代码 生日贺卡代码java

Java制作一个圣诞贺卡,求帮忙

太麻烦了不,为何想到用java做圣诞贺卡呢

创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的克什克腾网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

不同语言有不同适用场景,不好写呀 太简单了没意思,稍微难点又复杂

用java写一个新春贺卡,可转exe的

JAVA 做多媒体,不是强项

转 .exe 可以使用 exe4j

~

请求一个Java的贺卡applet实现

//background.java

import java.applet.AudioClip;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Container;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.MediaTracker;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import javax.swing.JApplet;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class background extends JPanel

{

private static final long serialVersionUID = -8251916094895167058L;

/**

* 居中

*/

public static final String CENTRE = "Centre";

/**

* 平铺

*/

public static final String TILED = "Tiled";

/**

* 拉伸

*/

public static final String SCALED = "Scaled";

/**

* 背景图片

*/

private Image backgroundImage;

/**

* 背景图片显示模式

*/

private String imageDisplayMode;

/**

* 背景图片显示模式索引(引入此属性有助于必要时扩展)

*/

private int modeIndex;

/**

* 构造一个没有背景图片的JImagePane

*/

public background()

{

this(null, CENTRE);

}

/**

* 构造一个具有指定背景图片和指定显示模式的JImagePane

* @param image 背景图片

* @param modeName 背景图片显示模式

*/

public background(Image image, String modeName)

{

super();

setBackgroundImage(image);

setImageDisplayMode(modeName);

}

/**

* 设置背景图片

* @param image 背景图片

*/

public void setBackgroundImage(Image image)

{

this.backgroundImage = image;

this.repaint();

}

/**

* 获取背景图片

* @return 背景图片

*/

public Image getBackgroundImage()

{

return backgroundImage;

}

/**

* 设置背景图片显示模式

* @param modeName 模式名称,取值仅限于ImagePane.TILED ImagePane.SCALED ImagePane.CENTRE

*/

public void setImageDisplayMode(String modeName)

{

if(modeName != null)

{

modeName = modeName.trim();

//居中

if(modeName.equalsIgnoreCase(CENTRE))

{

this.imageDisplayMode = CENTRE;

modeIndex = 0;

}

//平铺

else if(modeName.equalsIgnoreCase(TILED))

{

this.imageDisplayMode = TILED;

modeIndex = 1;

}

//拉伸

else if(modeName.equalsIgnoreCase(SCALED))

{

this.imageDisplayMode = SCALED;

modeIndex = 2;

}

this.repaint();

}

}

/**

* 获取背景图片显示模式

* @return 显示模式

*/

public String getImageDisplayMode()

{

return imageDisplayMode;

}

/**

* 绘制组件

* @see javax.swing.JComponent#paintComponent(Graphics)

*/

@Override

protected void paintComponent(Graphics g)

{

super.paintComponent(g);

//如果设置了背景图片则显示

if(backgroundImage != null)

{

int width = this.getWidth();

int height = this.getHeight();

int imageWidth = backgroundImage.getWidth(this);

int imageHeight = backgroundImage.getHeight(this);

switch(modeIndex)

{

//居中

case 0:

{

int x = (width - imageWidth) / 2;

int y = (height - imageHeight) / 2;

g.drawImage(backgroundImage, x, y, this);

break;

}

//平铺

case 1:

{

for(int ix = 0; ix width; ix += imageWidth)

{

for(int iy = 0; iy height; iy += imageHeight)

{

g.drawImage(backgroundImage, ix, iy, this);

}

}

break;

}

//拉伸

case 2:

{

g.drawImage(backgroundImage, 0, 0, width, height, this);

break;

}

}

}

}

}

//test.java

import java.applet.AudioClip;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

import javax.swing.*;

public class test extends JApplet implements Runnable{

Image img;

JButton b1;

Container hx;

background dd,dd1,dd2;

JLabel jl;

JButton jb,jb1;

JPanel jp,jp1;

int imgWidth,imgHeight;

AudioClip sound,sound1,sound2;

String m ="arash.wav";

String[] image ={"AA.PNG","CC.PNG","qq.png","uu.png","MM.PNG","tt.png"};

int count=0,count1=0;

Thread ShapeThread=null;

Random RandomNumber=new Random( );

Color ImageColor;

public void init(){

hx = getContentPane();

jp = new JPanel();

jp1 = new JPanel();

jl = new JLabel("Merry Christmas!");

jb1 = new JButton("变换背景图片");

jb1.setForeground(Color.blue);

jp.add(jb1);

jp.setOpaque(false);

jp1.add(jl);

jp1.setOpaque(false);

jl.setFont(new Font("隶书",Font.PLAIN,50));

img = getImage(getCodeBase(),image[0]);

dd = new background(img,dd.CENTRE);

dd.add(jp1);

dd.add(jp);

dd.setOpaque(false);

hx.add(dd);

sound = getAudioClip(getCodeBase(),m);

MediaTracker tracker = new MediaTracker(this);

tracker.addImage( img, 0 );

try

{

tracker.waitForID( 0 );

}catch(Exception e){}

imgWidth = img.getWidth(this);

imgHeight = img.getHeight(this);

jb1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String buttonName = e.getActionCommand();

if (buttonName.equals("变换背景图片")){

count ++;

img = getImage(getCodeBase(),image[count]);

dd.setVisible(false);

dd = new background(img,dd.CENTRE);

dd.add(jp1);

dd.add(jp);

hx.add(dd);

if(count == 5)

count = -1;

}

}

});

}

public void start(){

sound.loop();

if (ShapeThread==null)

{

ShapeThread=new Thread(this);

ShapeThread.start( );

}

}

public void stop(){

sound.stop();

}

public void run() {

// TODO Auto-generated method stub

while(true){

switch(RandomNumber.nextInt(3)) {

case 0:ImageColor=Color.green;break;

case 1:ImageColor=Color.yellow;break;

case 2:ImageColor=Color.orange;break;

default: ImageColor=Color.white;;

}

try{

ShapeThread.sleep(100);

jl.setForeground(ImageColor);

}catch(InterruptedException e)

{

e.printStackTrace();

}

}

}

}


分享名称:java贺卡代码 生日贺卡代码java
标题链接:http://cqwzjz.cn/article/hiieii.html