⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netbooksale.java.bak

📁 用来在IE中进行订购的程序源代码,已调试通过.
💻 BAK
📖 第 1 页 / 共 2 页
字号:
		if (e.target == pushButton4)
		{strContent=strContents[3];
		imageCurrent=imageBooks[3];
		}
		if (e.target == pushButton5)
		{strContent=strContents[4];
		imageCurrent=imageBooks[4];
		}
		if (e.target == pushButton6)
		{strContent=strContents[5];
		imageCurrent=imageBooks[5];
		}
		     
	     }
	      repaint();
	
		return true;
	}
	
	
	public void paint(Graphics g) 
	{	
            if(soundOK)
		{
			g.drawImage(imageCurrent,180, 150, appletImage);
		}
		else
		{
			g.drawString("正在装载图片,请稍后...", 0, 0);
		}

      
		paintComponents(g);
		totleprice.setText(String.valueOf(price));
		textContent.setText(strContent);
	
	}
	
	public void update(Graphics g)
	{
		paint(g);
	}

}


//实现滚动效果
class CRollTitle extends Panel
implements Runnable 
{	
	Thread threadTitle = null;
    	String strTitle;
	Font fontTitle;
	int x1 = 0;
	int x2 = 0;
	int newx1 = 0;
	int newx2 = 0;
	FontMetrics metrics;
	
	public CRollTitle(String strTitle)
	{
		this.strTitle = strTitle;
		GridBagLayout layout = new GridBagLayout();
		setLayout(layout);
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.NONE;
		c.anchor = GridBagConstraints.WEST;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.weightx = 1;
		c.weighty = 1;
	
		Label labelNone; //加空标签增高位置
		for(int i=0; i<3; i++)	
		{
			labelNone = new Label(" ");
			layout.setConstraints(labelNone, c);
			add(labelNone);
		}
		
         	fontTitle = new Font("楷体", Font.BOLD, 40);
    		metrics = getFontMetrics(fontTitle);		
	} 
	
	public  void paint(Graphics g) 
	{	
		g.setFont(fontTitle);
		g.setColor(Color.red);
		g.drawString(strTitle, x1, 40);
		x2 = x1-metrics.stringWidth(strTitle)-100; //第二条标题的X坐标
		g.drawString(strTitle, x2, 40);
		newx1 = x1; 
		newx2 = x2;
	}
	
	public void update(Graphics g)//用背景色抹掉以前的标题
	{
		g.setFont(fontTitle);
		g.setColor(getBackground());
		g.drawString(strTitle, newx1, 40); 
		g.drawString(strTitle, newx2, 40);
		paint(g);
	}
	
	public void start()
	{
		if(threadTitle == null)
		{
			threadTitle = new Thread(this);
			threadTitle.start();
		}
	}
	public void run() 
	{
		for(;;)//标题向右移动
		{
			x1 += 20; 
			if( (x1+metrics.stringWidth(strTitle)) >750 )
			{
				x1 = x2;
				x2 = x1-metrics.stringWidth(strTitle)-50;
			}
			try {Thread.sleep(300);} 
			catch (InterruptedException e){}
			repaint();
			
		}		
	}
	public void stop()
	{
		if(threadTitle != null)
		{
			threadTitle.stop();
			threadTitle = null;
		}
	}
}


//实现按钮类
class CBookButton extends Panel
{	
	AudioClip audio,audio1;
	Applet appletSound;
	String strSound = "spacemusic.au";
	String strSound1 = "gong.au";
	String strContents[];
	String strContent;
	final int  BOOKCOUNT=6;
	
	boolean bSound = true;
	Button buttonSound;
	Button Buybutton;
	CFrameThank frameThank;
	TextArea textContent;
	
	public CBookButton(Applet applet1)
	{
		//通过HTM语句的参数加载声音文件
		this.appletSound = applet1;
		String strParam = appletSound.getParameter("SoundFile");
		String strParam1 = appletSound.getParameter("SoundFile1");
		if(strParam != null)
		{
			strSound = strParam;
			strSound1 = strParam1;
		}
		bSound = true;
		audio = appletSound.getAudioClip(appletSound.getCodeBase(), strSound);
		audio1 = appletSound.getAudioClip(appletSound.getCodeBase(), strSound1);
		
		//小窗口的实例
		frameThank = new CFrameThank("谢谢你的光临");
		frameThank.resize(350, 250);
		
		GridLayout layout = new GridLayout(2, 1);
		setLayout(layout); 
		
		buttonSound = new Button("音效:开/关");
		add(buttonSound);
		
		Buybutton = new Button("购  买");
		add(Buybutton);
		
		//初始化声音
		if(bSound)
		{
			audio.loop();
		}

	} 	
	public void paint(Graphics g) 
	{
    		paintComponents(g);		
	}
	public void update(Graphics g)
	{
		paint(g);
	}
	
	public boolean action(Event e, Object what) 
	{
		
		//响应购买按钮显示小窗口类
		
		if(e.target.equals(Buybutton))
		{
			frameThank.strName =CBookImage.stringCurrent;
			frameThank.textName.setText(frameThank.strName);
			frameThank.strPrice=(String.valueOf(CBookImage.price)+"元");
			frameThank.labelPrice.setText(frameThank.strPrice);
			frameThank.show();
			audio1.play();
		}
		//启动或停止声音的播放
		if(e.target.equals(buttonSound))
		{
			bSound = !bSound;
			if(bSound)
			{
				audio.loop();
			}
			else
			{
				audio.stop();
			}
			
		}
		return true;
	}
}

//实现小窗口
class CFrameThank extends Frame
{
	TextArea textName;
	String strName = "";	
	Label labelPrice;
	String strPrice = "";
	Button buttonReturn;
	Font  f;
	public CFrameThank(String strTitle)
	{
		super(strTitle);
		
		GridBagLayout layout = new GridBagLayout();
		setLayout(layout);  
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		c.gridwidth = GridBagConstraints.REMAINDER;
		c.weightx = 1;
		c.weighty = 1;
		
		Label labelThank = new Label("网上购书,物超所值");
		f=new Font("楷体", Font.BOLD, 20);
		labelThank.setFont(f);
		layout.setConstraints(labelThank, c);
		add(labelThank);
		
		Label labelNone = new Label("您购买了:");
		c.gridwidth = GridBagConstraints.RELATIVE;
		layout.setConstraints(labelNone, c);
		add(labelNone);
		textName = new TextArea(strName,6,20);
		c.gridwidth = GridBagConstraints.REMAINDER;
		layout.setConstraints(textName, c);
		add(textName);
		
		labelNone = new Label("价格:");
		c.gridwidth = GridBagConstraints.RELATIVE;
		layout.setConstraints(labelNone, c);
		add(labelNone);
		labelPrice = new Label(strPrice);
		c.gridwidth = GridBagConstraints.REMAINDER;
		layout.setConstraints(labelPrice, c);
		add(labelPrice);
		
		
		c.gridwidth = GridBagConstraints.RELATIVE;
		for(int i=0; i<1; i++)
		{
			labelNone = new Label("      ");
			layout.setConstraints(labelNone, c);
			add(labelNone);
		}
		c.gridwidth = GridBagConstraints.REMAINDER;
		buttonReturn = new Button("关闭窗口");
		layout.setConstraints(buttonReturn, c);
		add(buttonReturn);
		
	}
	public void paint(Graphics g) 
	{
		labelPrice.setText(strPrice);
		textName.setText(strName);
		paintComponents(g);
	}
	public boolean action(Event e, Object what) 
	{
		if(e.target.equals(buttonReturn))
		{
			this.hide(); 
		}
		return true;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -