1.急需基于eclipse的实战JAVA小游戏源代码!!小项!目源码
2.java小程序源代码,实战简单点的小项,100多行,目源码ios软件源码修改谁有啊
3.求一个简单又有趣的实战JAVA小游戏代码
急需基于eclipse的JAVA小游戏源代码!!小项!目源码
单人版五子棋,实战不用导入,小项直接新建一个mywindow类就行,目源码然后把一下代码粘贴就Ok了。实战或者,小项直接用dos就可以了。目源码爱心筹源码下载。
---------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess[][] = new int[][];
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i < ;i++)
{
for(int j = 0;j < ;j++)
{
chess[i][j] = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, , );
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x < || x > + ||y < || y > +)
{
return;
}
if(chess[x/-1][y/-1] != 0)
{
return;
}
if(Is_Black_True == true)
{
chess[x/-1][y/-1] = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess[x/-1][y/-1] = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = ;i <= ;i += )
{
for(int j = ;j <= ; j+= )
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, );
}
}
for(int j = ;j <= ;j += )
{
g.setColor(Color.WHITE);
g.drawLine(, j, , j);
}
}
void Drawchess(Graphics g)
{
for(int i = 0;i < ;i++)
{
for(int j = 0;j < ;j++)
{
if(chess[i][j] == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * - 8, (j + 1) * - 8, , );
}
if(chess[i][j] == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * - 8, (j + 1) * - 8, , );
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i < ;i++)//横向判断
{
for(int j = 0;j < ;j++)
{
if(chess[i][j] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i][j] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i < ;i++)//竖向判断
{
for(int j = 0;j < ;j++)
{
if(chess[j][i] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[j][i] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i < 7;i++)//左向右斜判断
{
for(int j = 0;j < 7;j++)
{
for(int k = 0;k < 5;k++)
{
if(chess[i + k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i + k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
for(i = 4;i < ;i++)//右向左斜判断
{
for(int j = 6;j >= 0;j--)
{
for(int k = 0;k < 5;k++)
{
if(chess[i - k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i - k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
}
void Clear_Chess()
{
for(int i=0;i<;i++)
{
for(int j=0;j<;j++)
{
chess[i][j]=0;
}
}
repaint();
}
public void paint(Graphics g)
{
Drawline(g);
Drawchess(g);
}
public void mouseExited(MouseEvent e){ }
public void mouseEntered(MouseEvent e){ }
public void mouseReleased(MouseEvent e){ }
public void mouseClicked(MouseEvent e){ }
}
class myframe extends Frame implements WindowListener
{
mypanel panel;
myframe()
{
setLayout(null);
panel = new mypanel();
add(panel);
panel.setBounds(0,, , );
setTitle("单人版五子棋");
setBounds(, , , );
setVisible(true);
addWindowListener(this);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e){ }
public void windowActivated(WindowEvent e){ }
public void windowOpened(WindowEvent e){ }
public void windowClosed(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
}
public class mywindow
{
public static void main(String argc [])
{
myframe f = new myframe();
}
}
java小程序源代码,简单点的,多行,谁有啊
// My car shop.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class carshop extends JFrame
{
// JPanel to hold all pictures
private JPanel windowJPanel;
private String[] cars = { "","阿斯顿马丁", "美洲虎", "凯迪拉克",
"罗孚", "劳斯莱斯","别克"};
private int[] jiage = { 0,, , ,
, , };
// JLabels for first snack shown
private JLabel oneJLabel;
private JLabel oneIconJLabel;
// JLabels for second snack shown
private JLabel twoJLabel;
private JLabel twoIconJLabel;
// JLabels for third snack shown
private JLabel threeJLabel;
private JLabel threeIconJLabel;
// JLabels for fourth snack shown
private JLabel fourJLabel;
private JLabel fourIconJLabel;
// JLabels for fifth snack shown
private JLabel fiveJLabel;
private JLabel fiveIconJLabel;
// JLabels for sixth snack shown
private JLabel sixJLabel;
private JLabel sixIconJLabel;
// JTextField for displaying snack price
private JTextArea displayJTextArea;
// JLabel and JTextField for user input
private JLabel inputJLabel;
private JComboBox selectCountryJComboBox;
private JLabel inputJLabel2;
private JTextField inputJTextField2;
// JButton to enter user input
private JButton enterJButton;
//JButton to clear the components
private JButton clearJButton;
// no-argument constructor
public carshop()
{
createUserInterface();
}
// create and position GUI components; register event handlers
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();
// enable explicit positioning of GUI components
contentPane.setLayout( null );
// set up windowJPanel
windowJPanel = new JPanel();
windowJPanel.setBounds( , , , );
windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
windowJPanel.setLayout( null );
contentPane.add( windowJPanel );
// set up oneIconJLabel
oneIconJLabel = new JLabel();
oneIconJLabel.setBounds( , , , );
oneIconJLabel.setIcon( new ImageIcon( "images/阿斯顿马丁.jpg" ) );
windowJPanel.add( oneIconJLabel );
// set up oneJLabel
oneJLabel = new JLabel();
oneJLabel.setBounds( , , , );
oneJLabel.setText( "阿斯顿马丁" );
oneJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( oneJLabel );
// set up twoIconJLabel
twoIconJLabel = new JLabel();
twoIconJLabel.setBounds( , , , );
twoIconJLabel.setIcon( new ImageIcon( "images/美洲虎.jpg" ) );
windowJPanel.add( twoIconJLabel );
// set up twoJLabel
twoJLabel = new JLabel();
twoJLabel.setBounds( , , , );
twoJLabel.setText( "美洲虎" );
twoJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( twoJLabel );
// set up threeIconJLabel
threeIconJLabel = new JLabel();
threeIconJLabel.setBounds( , , , );
threeIconJLabel.setIcon( new ImageIcon(
"images/凯迪拉克.jpg" ) );
windowJPanel.add( threeIconJLabel );
// set up threeJLabel
threeJLabel = new JLabel();
threeJLabel.setBounds( , , , );
threeJLabel.setText( "凯迪拉克" );
threeJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( threeJLabel );
// set up fourIconJLabel
fourIconJLabel = new JLabel();
fourIconJLabel.setBounds( , , , );
fourIconJLabel.setIcon( new ImageIcon( "images/罗孚.jpg" ) );
windowJPanel.add( fourIconJLabel );
// set up fourJLabel
fourJLabel = new JLabel();
fourJLabel.setBounds( , , , );
fourJLabel.setText( "罗孚" );
fourJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fourJLabel );
// set up fiveIconJLabel
fiveIconJLabel = new JLabel();
fiveIconJLabel.setBounds( , , , );
fiveIconJLabel.setIcon( new ImageIcon(
"images/劳斯莱斯.jpg" ) );
windowJPanel.add( fiveIconJLabel );
// set up fiveJLabel
fiveJLabel = new JLabel();
fiveJLabel.setBounds( , , , );
fiveJLabel.setText( "劳斯莱斯" );
fiveJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fiveJLabel );
// set up sixIconJLabel
sixIconJLabel = new JLabel();
sixIconJLabel.setBounds( , , , );
sixIconJLabel.setIcon( new ImageIcon( "images/别克.jpg" ) );
windowJPanel.add( sixIconJLabel );
// set up sixJLabel
sixJLabel = new JLabel();
sixJLabel.setBounds( , , , );
sixJLabel.setText( "别克" );
sixJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( sixJLabel );
// set up enterJButton
enterJButton = new JButton();
enterJButton.setBounds( , , , );
enterJButton.setText( "Enter" );
contentPane.add( enterJButton );
enterJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when enterJButton is clicked
public void actionPerformed( ActionEvent event )
{
enterJButtonActionPerformed( event );
}
} // end anonymous inner class
); // end call to addActionListener
// set up clearJButton
clearJButton = new JButton();
clearJButton.setBounds( , , , );
clearJButton.setText( "Clear" );
contentPane.add( clearJButton );
// set up inputJLabel
inputJLabel = new JLabel();
inputJLabel.setBounds( , , , );
inputJLabel.setText( "Please make selection:" );
contentPane.add( inputJLabel );
selectCountryJComboBox = new JComboBox( cars );
selectCountryJComboBox.setBounds( , , , );
selectCountryJComboBox.setMaximumRowCount( 3 );
contentPane.add( selectCountryJComboBox );
// set up inputJTextField
inputJLabel2 = new JLabel();
inputJLabel2.setBounds( , , , );
inputJLabel2.setText( "Input the Numble:" );
contentPane.add( inputJLabel2 );
// set up inputJTextField
inputJTextField2 = new JTextField();
inputJTextField2.setBounds( , , , );
inputJTextField2.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( inputJTextField2 );
clearJButton.addActionListener(
new ActionListener() // anonymous inner class
{
// event handler called when clearJButton is clicked
public void actionPerformed( ActionEvent event )
{
clearJButtonActionPerformed( event );
}
} // end anonymous inner class
);
// set up displayJTextField
displayJTextArea = new JTextArea();
displayJTextArea.setBounds( , ,, );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( , ); // set window size
setVisible( true ); // display window
} // end method createUserInterface
private void clearJButtonActionPerformed( ActionEvent event )
{
// clear the JTextFields
inputJTextField2.setText( "" );
displayJTextArea.setText("");
} // end method clearJButtonActionPerformed
private void enterJButtonActionPerformed( ActionEvent event )
{
double z;
double c;
int x;
int y;
x=selectCountryJComboBox.getSelectedIndex();
y=Integer.parseInt(inputJTextField2.getText());
double discountRate;
int amount = Integer.parseInt( inputJTextField2.getText());
switch (amount/5)
{
case 0:
discountRate = 0;
break;
case 1:
discountRate = 1;
break;
case 2:
discountRate = 2;
break;
case 3:
discountRate = 3;
break;
default:
discountRate = 4;
} // end switch statement
c=1-discountRate/;
z=jiage[x]*y*c;
displayJTextArea.append("你选择的是:"+cars[x]+";"+
"它的单价是:"+jiage[x]+";" +"你购买该产品的数量是:"+y+"," +"\n"+"该数量的折扣是:"
+discountRate + " %"+";"+"本次消费的总价格是:"+z+"元"+"!"+"\n");
}
public static void main( String args[] )
{
carshop application = new carshop();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
} // end class carshop
求一个简单又有趣的JAVA小游戏代码
以下是根据您的要求对文本内容进行修改和润色后的结果:
1. 游戏名称:连连看
2. 源代码简介:
本程序采用Java Swing库设计开发,创建了一个连连看游戏框架。网站影视搜索源码游戏界面包含6行5列共个宝石按钮,以及三个功能按钮(退出、重置、重新开始),并有一个显示分数的标签。
3. 游戏逻辑:
- 宝石按钮的位置坐标被存储在一个二维数组中。
- 定义了两个变量来记录被选中的辅助游戏菜单源码按钮。
- 有一个静态变量来判断是否有按钮被选中。
- 游戏通过检测两个被选中的按钮是否符合连连看的消除规则来执行消除操作。
4. 代码说明:
- 变量和方法的命名应遵循Java编程规范,例如将“diamondsButton”更改为“diamondsButtons”。
- “grid”数组的声明应改为私有,因为它是类的成员变量。
- 类名“lianliankan”应与文件名一致。区块链 空投 源码
- 应删除不相关的代码段,例如关于代码页的解释。
- 需要添加缺失的分号、括号和引号。
- 为避免混淆,变量名“i, j, k, n”应更具描述性。
5. 界面与交互:
- 界面布局需要使用专业的UI设计原则。
- 功能按钮和分数标签应该有适当的位置和大小。
- 游戏按钮应该具有统一的样式和大小。
6. 游戏玩法:
- 玩家需要点击并连接两个相同的宝石按钮以消除它们。
- 被消除的按钮会从界面上消失,并更新分数。
- 游戏的目标是在限定的时间内尽可能多地消除宝石。
7. 错误修正:
- 应修正打字错误,例如将“蔽岩扮”更正为“编撰”,“宏灶”更正为“宏量”。
- 确保所有的类、方法和变量定义都符合Java语法规则。
8. 性能优化:
- 考虑使用更有效的数据结构来存储和管理宝石按钮的位置。
- 优化消除逻辑,确保游戏运行流畅。
通过以上修改,不仅提升了代码的可读性和可维护性,也确保了游戏的逻辑清晰、界面友好。