1. 求一份java PC版的仿天天酷跑的的源代碼!
哪個沒事做 去做這個仿碼哦
2. 那個大神有完整的java,eclipse,2048游戲的源代碼,全部拷貝粘貼就能用的,給一個,在線等,急!!!
網上的java代碼在eclipse里運行方法:
1.打開eclipse,點擊項目的空白處,選擇import;
2.選擇Existing Project into Workspace,點擊next,找到的java代碼,導入到eclipse中;
3.導入成功之後,選擇項目,滑鼠右鍵,選擇run as,選擇一個運行方式,然後運行即可。
3. 求"貪吃蛇"小游戲JAVA源代碼一份
貪吃蛇
import
java.awt.*;
import
java.awt.event.*;
public
class
GreedSnake
//主類
{
/**
*
@param
args
*/
public
static
void
main(String[]
args)
{
//
TODO
Auto-generated
method
stub
new
MyWindow();
}
}
class
MyPanel
extends
Panel
implements
KeyListener,Runnable//自定義面板類,繼承了鍵盤和線程介面
{
Button
snake[];
//定義蛇按鈕
int
shu=0;
//蛇的節數
int
food[];
//食物數組
boolean
result=true;
//判定結果是輸
還是贏
Thread
thread;
//定義線程
static
int
weix,weiy;
//食物位置
boolean
t=true;
//判定游戲是否結束
int
fangxiang=0;
//蛇移動方向
int
x=0,y=0;
//蛇頭位置
MyPanel()
{
setLayout(null);
snake=new
Button[20];
food=new
int
[20];
thread=new
Thread(this);
for(int
j=0;j<20;j++)
{
food[j]=(int)(Math.random()*99);//定義20個隨機食物
}
weix=(int)(food[0]*0.1)*60;
//十位*60為橫坐標
weiy=(int)(food[0]%10)*40;
//個位*40為縱坐標
for(int
i=0;i<20;i++)
{
snake[i]=new
Button();
}
add(snake[0]);
snake[0].setBackground(Color.black);
snake[0].addKeyListener(this);
//為蛇頭添加鍵盤監視器
snake[0].setBounds(0,0,10,10);
setBackground(Color.cyan);
}
public
void
run()
//接收線程
{
while(t)
{
if(fangxiang==0)//向右
{
try
{
x+=10;
snake[0].setLocation(x,
y);//設置蛇頭位置
if(x==weix&&y==weiy)
//吃到食物
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
//重繪下一個食物
add(snake[shu]);
//增加蛇節數和位置
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
//睡眠100ms
}
catch(Exception
e){}
}
else
if(fangxiang==1)//向左
{
try
{
x-=10;
snake[0].setLocation(x,
y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
}
catch(Exception
e){}
}
else
if(fangxiang==2)//向上
{
try
{
y-=10;
snake[0].setLocation(x,
y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
}
catch(Exception
e){}
}
else
if(fangxiang==3)//向下
{
try
{
y+=10;
snake[0].setLocation(x,
y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
}
catch(Exception
e){}
}
int
num1=shu;
while(num1>1)//判斷是否咬自己的尾巴
{
if(snake[num1].getBounds().x==snake[0].getBounds().x&&snake[num1].getBounds().y==snake[0].getBounds().y)
{
t=false;
result=false;
repaint();
}
num1--;
}
if(x<0||x>=this.getWidth()||y<0||y>=this.getHeight())//判斷是否撞牆
{
t=false;
result=false;
repaint();
}
int
num=shu;
while(num>0)
//設置蛇節位置
{
snake[num].setBounds(snake[num-1].getBounds());
num--;
}
if(shu==15)
//如果蛇節數等於15則勝利
{
t=false;
result=true;
repaint();
}
}
}
public
void
keyPressed(KeyEvent
e)
//按下鍵盤方向鍵
{
if(e.getKeyCode()==KeyEvent.VK_RIGHT)//右鍵
{
if(fangxiang!=1)//如果先前方向不為左
fangxiang=0;
}
else
if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
if(fangxiang!=0)
fangxiang=1;
}
else
if(e.getKeyCode()==KeyEvent.VK_UP)
{
if(fangxiang!=3)
fangxiang=2;
}
else
if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
if(fangxiang!=2)
fangxiang=3;
}
}
public
void
keyTyped(KeyEvent
e)
{
}
public
void
keyReleased(KeyEvent
e)
{
}
public
void
paint(Graphics
g)
//在面板上繪圖
{
int
x1=this.getWidth()-1;
int
y1=this.getHeight()-1;
g.setColor(Color.red);
g.fillOval(weix,
weiy,
10,
10);//食物
g.drawRect(0,
0,
x1,
y1);
//牆
if(t==false&&result==false)
g.drawString("GAME
OVER!",
250,
200);//輸出遊戲失敗
else
if(t==false&&result==true)
g.drawString("YOU
WIN!",
250,
200);//輸出遊戲成功
}
}
class
MyWindow
extends
Frame
implements
ActionListener//自定義窗口類
{
MyPanel
my;
Button
btn;
Panel
panel;
MyWindow()
{
super("GreedSnake");
my=new
MyPanel();
btn=new
Button("begin");
panel=new
Panel();
btn.addActionListener(this);
panel.add(new
Label("begin後請按Tab鍵選定蛇"));
panel.add(btn);
panel.add(new
Label("按上下左右鍵控制蛇行動"));
add(panel,BorderLayout.NORTH);
add(my,BorderLayout.CENTER);
setBounds(100,100,610,500);
setVisible(true);
validate();
addWindowListener(new
WindowAdapter()
{
public
void
windowClosing(WindowEvent
e)
{
System.exit(0);
}
});
}
public
void
actionPerformed(ActionEvent
e)//按下begin按鈕
{
if(e.getSource()==btn)
{
try
{
my.thread.start();
//開始線程
my.validate();
}
catch(Exception
ee){}
}
}
}
4. 求java小游戲源代碼
[最佳答案] 連連看java源代碼 import javax.swing.*; import java.awt.*; import java.awt.event.*; pu... int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位...
5. java網路游戲源代碼下載
這是游戲公司的最高度機密。。。哪可能有啊。。
而且只用JAVA是做不出網路游戲的。。
要是代碼被知道的話,黑客直接進游戲哪東西,都不用知道別人賬號密碼
6. 求一個簡單的Java小游戲的代碼
連連看的小源碼
package Lianliankan;
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];//游戲按鈕數組
JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕
JLabel fractionLable=new JLabel("0"); //分數標簽
JButton firstButton,secondButton; //分別記錄兩次被選中的按鈕
int grid[][] = new int[8][7];//儲存游戲按鈕位置
static boolean pressInformation=false; //判斷是否有按鈕被選中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標
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("再來一局");
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; //這里一定要將按鈕點擊信息歸為初始
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() { //相同的情況下能不能消去。仔細分析,不一條條注釋
if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判斷是否相鄰
remove();
}
else{
for (j=0;j<7;j++ ) {
if (grid[x0][j]==0){ //判斷第一個按鈕同行哪個按鈕為空
if (y>j) { //如果第二個按鈕的Y坐標大於空按鈕的Y坐標說明第一按鈕在第二按鈕左邊
for (i=y-1;i>=j;i-- ){ //判斷第二按鈕左側直到第一按鈕中間有沒有按鈕
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1說明通過了第一次驗證
}
if (k==1) {
linePassOne();
}
}
if (y<j){ //如果第二個按鈕的Y坐標小於空按鈕的Y坐標說明第一按鈕在第二按鈕右邊
for (i=y+1;i<=j ;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 (x0<x) {
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 (x0>x) {
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;i<8;i++ ) { //列
if (grid[i][y0]==0) {
if (x>i) {
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) {
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 (y0<y) {
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 (y0>y) {
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 (y0>j){ //第一按鈕同行空按鈕在左邊
for (i=y0-1;i>=j ;i-- ){ //判斷第一按鈕同左側空按鈕之間有沒按鈕
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2說明通過了第二次驗證
}
}
if (y0<j){ //第一按鈕同行空按鈕在與第二按鈕之間
for (i=y0+1;i<=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0>i) {
for (j=x0-1;j>=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0<i) {
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
7. J2EE貪吃蛇游戲源代碼
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
/**
*
* @author lenovo
*/
public class TanChiShe extends JFrame implements ActionListener, KeyListener,Runnable{
private JMenuBar menuBar;
private JMenu youXiMenu,nanDuMenu,fenShuMenu,guanYuMenu;
private JMenuItem kaiShiYouXi,exitItem,zuoZheItem,fenShuItem;
private JCheckBoxMenuItem cJianDan,cPuTong,cKunNan;
private int length = 6;
private Toolkit toolkit;
private int i,x,y,z,objectX,objectY,object=0,growth=0,time;//bojectX,Y為食物坐標,z為蛇前進方向
private int difficult=2;
private int m[]=new int[50];
private int n[]=new int[50];
private Thread she = null;
private int life=0;
private int foods = 0;
private int fenshu=0;
public void run()
{
time=500;
for(i=0;i<=length-1;i++)
{
m[i]=90-i*10;n[i]=60;
}
x=m[0];
y=n[0];
z=4;
while(she!=null)
{
check();
try
{
she.sleep(time);
}
catch(Exception ee)
{
System.out.println(z+"");
}
}
}
public TanChiShe()
{
//***************創建新對象**************
setVisible(true);
menuBar = new JMenuBar();
Container con=getContentPane();
toolkit=getToolkit();
//**************游戲菜單對象*****************
youXiMenu = new JMenu("游戲");
kaiShiYouXi = new JMenuItem("開始游戲");
exitItem = new JMenuItem("退出遊戲");
//***************困難程度對象****************
nanDuMenu = new JMenu("困難程度");
cJianDan = new JCheckBoxMenuItem("簡單");
cPuTong = new JCheckBoxMenuItem("普通");
cKunNan = new JCheckBoxMenuItem("困難");
//*****************分數菜單對象****************
fenShuMenu = new JMenu("積分排行");
fenShuItem = new JMenuItem("最高記錄");
//****************關於對象*********************
guanYuMenu = new JMenu("關於");
zuoZheItem = new JMenuItem("關於作者");
//***************設置關於菜單*******************
guanYuMenu.add(zuoZheItem);
//****************設置困難程度菜單**************
nanDuMenu.add(cJianDan);
nanDuMenu.add(cPuTong);
nanDuMenu.add(cKunNan);
//******************設置分數菜單***************
fenShuMenu.add(fenShuItem);
//*****************設置游戲菜單****************
youXiMenu.add(kaiShiYouXi);
youXiMenu.add(exitItem);
//******************設置主菜單********************
menuBar.add(youXiMenu);
menuBar.add(nanDuMenu);
menuBar.add(fenShuMenu);
menuBar.add(guanYuMenu);
//*********************監聽注冊*****************
zuoZheItem.addActionListener(this);
kaiShiYouXi.addActionListener(this);
exitItem.addActionListener(this);
addKeyListener(this);
fenShuItem.addActionListener(this);
//*********************加快捷鍵********************
KeyStroke keyOpen = KeyStroke.getKeyStroke('O',InputEvent.CTRL_DOWN_MASK);
kaiShiYouXi.setAccelerator(keyOpen);
KeyStroke keyExit = KeyStroke.getKeyStroke('X',InputEvent.CTRL_DOWN_MASK);
exitItem.setAccelerator(keyExit);
//*****************設置框架**********************
setJMenuBar(menuBar);
setTitle("貪吃蛇");
setResizable(false);
setBounds(300,200,400,400);
validate();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[])
{
TanChiShe 高原=new TanChiShe();
}
//******************菜單監聽******************************
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==kaiShiYouXi)
{
length = 6;
life = 0;
foods = 0;
if(she==null)
{
she=new Thread(this);
she.start();
}
else if(she!=null)
{
she=null;
she= new Thread(this);
she.start();
}
}
if(e.getSource()==exitItem)
{
System.exit(0);
}
if(e.getSource()==zuoZheItem)
{
JOptionPane.showMessageDialog(this, "北京java編程愛好者製作"+"\n\n"+" "+"QQ號:860695120"+"\n");
}
if(e.getSource()==fenShuItem)
{
JOptionPane.showMessageDialog(this,"最高記錄為"+fenshu+"");
}
}
//**************檢查一下*******************************
public void check()
{
isDead();
if(she!=null)
{
if(growth==0)
{
reform(); //得到食物
}
else
{
upgrowth(); //生成食物
}
if(x==objectX&&y==objectY)
{
object=0;
growth=1;
toolkit.beep();
}
//****************產生食物坐標**********************
if(object==0)
{
object=1;
objectX=(int)Math.floor(Math.random()*39)*10;
objectY=(int)Math.floor(Math.random()*29)*10+50;
}
this.repaint(); //重繪
}
}
void isDead()
{
//判斷游戲是否結束的方法
if(z==4)
{
x=x+10;
}
else if(z==3)
{
x=x-10;
}
else if(z==2)
{
y=y+10;
}
else if(z==1)
{
y=y-10;
}
if(x<0||x>390||y<50||y>390)
{
she=null;
}
for(i=1;i<length;i++)
{
if(m[i]==x&&n[i]==y)
{
she=null;
}
}
}
public void upgrowth()
{
//當蛇吃到東西時的方法
if(length<50)
{
length++;
}
growth--;
time=time-10;
reform();
life+=100;
if(fenshu<life)
{
fenshu = life;
}
foods++;
}
public void reform()
{
for(i=length-1;i>0;i--)
{
m[i]=m[i-1];
n[i]=n[i-1];
}
if(z==4)
{
m[0]=m[0]+10;
}
if(z==3)
{
m[0]=m[0]-10;
}
if(z==2)
{
n[0]=n[0]+10;
}
if(z==1)
{
n[0]=n[0]-10;
}
}
public void keyPressed(KeyEvent e)
{
if(she!=null)
{
if(e.getKeyCode()==KeyEvent.VK_UP)
{
if(z!=2)
{
z=1;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
if(z!=1)
{
z=2;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
if(z!=4)
{
z=3;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
if(z!=3)
{
z=4;
check();
}
}
}
}
public void keyReleased(KeyEvent e)
{
// TODO 自動生成方法存根
}
public void keyTyped(KeyEvent e)
{
// TODO 自動生成方法存根
}
public void paint(Graphics g)
{
//*******************畫圖**********************
g.setColor(Color.DARK_GRAY); //設置背景
g.fillRect(0,50,400,400);
g.setColor(Color.pink);
for(i=0;i<=length-1;i++)
{
g.fillRect(m[i],n[i],10,10);
}
g.setColor(Color.green); //蛇的食物
g.fillRect(objectX,objectY,10,10);
g.setColor(Color.white);
g.drawString("當前 分數"+this.life,6,60);
g.drawString("當前已吃食物數"+this.foods,6,72);
}
}
8. 求一個簡單又有趣的JAVA小游戲代碼
具體如下:
連連看的小源碼
package Lianliankan;
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];//游戲按鈕數組
JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕
JLabel fractionLable=new JLabel("0"); //分數標簽
JButton firstButton,secondButton; //
分別記錄兩次被選中的按鈕
int grid[][] = new int[8][7];//儲存游戲按鈕位置
static boolean pressInformation=false; //判斷是否有按鈕被選中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標
int i,j,k,n;//消除方法控制
代碼(code)是程序員用開發工具所支持的語言寫出來的源文件,是一組由字元、符號或信號碼元以離散形式表示信息的明確的規則體系。
對於字元和Unicode數據的位模式的定義,此模式代表特定字母、數字或符號(例如 0x20 代表一個空格,而 0x74 代表字元「t」)。一些數據類型每個字元使用一個位元組;每個位元組可以具有 256 個不同的位模式中的一個模式。
在計算機中,字元由不同的位模式(ON 或 OFF)表示。每個位元組有 8 位,這 8 位可以有 256 種不同的 ON 和 OFF 組合模式。對於使用 1 個位元組存儲每個字元的程序,通過給每個位模式指派字元可表示最多 256 個不同的字元。2 個位元組有 16 位,這 16 位可以有 65,536 種唯一的 ON 和 OFF 組合模式。使用 2 個位元組表示每個字元的程序可表示最多 65,536 個字元。
單位元組代碼頁是字元定義,這些字元映射到每個位元組可能有的 256 種位模式中的每一種。代碼頁定義大小寫字元、數字、符號以及 !、@、#、% 等特殊字元的位模式。每種歐洲語言(如德語和西班牙語)都有各自的單位元組代碼頁。
雖然用於表示 A 到 Z 拉丁字母表字元的位模式在所有的代碼頁中都相同,但用於表示重音字元(如"é"和"á")的位模式在不同的代碼頁中卻不同。如果在運行不同代碼頁的計算機間交換數據,必須將所有字元數據由發送計算機的代碼頁轉換為接收計算機的代碼頁。如果源數據中的擴展字元在接收計算機的代碼頁中未定義,那麼數據將丟失。
如果某個資料庫為來自許多不同國家的客戶端提供服務,則很難為該資料庫選擇這樣一種代碼頁,使其包括所有客戶端計算機所需的全部擴展字元。而且,在代碼頁間不停地轉換需要花費大量的處理時間。