
正文
免费JAVA长代码 找java代码的免费网站
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求java窗体代码,可以显示默认长文本,代码格式最好规范可以直接使用。
importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.util.*;importjavax.swing.*;/***多线程,小球演示.打开Windows任务管理器,可看到线程变化。可搜索到,run()方法/.start()**du:程序技巧体会:所谓产生一个小球,即是new其类对象,其属性携带画小球免费JAVA长代码的坐标、颜色、所在容器等参数。**一个类,属性用来作为参数容器用,方法.完成功能。**///运行类publicclassBouncePress{//publicstaticvoidmain(String[]args){JFrameframe=newBouncePressFrame();//生成窗口。执行构造。-----业务逻辑。frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//similarto//window//listenerframe.show();}}classBouncePressFrameextendsJFrame{privateBallPressCanvascanvas;publicBouncePressFrame(){setSize(600,500);//窗口大小setTitle("BounceBall");ContainercontentPane=getContentPane();//Swing的窗口不能直接放入东西,只能在其上的ContentPane上放。canvas=newBallPressCanvas();//生成一个新面板。-----canvascontentPane.add(canvas,BorderLayout.CENTER);//窗口中心加入该面板。JPanelbuttonPanel=newJPanel();//再生成一个新面板。----buttonPanel//调用本类方法addButton。addButton(buttonPanel,"Start",//生成一个按钮"Start"---加入面板buttonPanelnewActionListener(){//|------按钮绑上action监听器。publicvoidactionPerformed(ActionEventevt){//|小球容器对象的addBall(Thread.NORM_PRIORITY-4,Color.black);//事件处理时,执行---addBall()方法。---产生小球(参数对象)---加入List中---开始画球。}});//按一次,addBall()一次---产生一个新小球---加入List中---开始画此新小球。//---画球线程BallPressThread的run()---小球(参数对象).move()---每次画时,先移动,再判断,再画。//---BallPressCanvas类的canvas对象.paint()---自动调BallPressCanvas类的paintComponent(Graphics//g)方法。//---该方法,从List中循环取出所有小球,第i个球,---调该小球BallPress类//.draw()方法---调Graphics2D方法画出小球。--使用color/addButton(buttonPanel,"Express",newActionListener(){publicvoidactionPerformed(ActionEventevt){addBall(Thread.NORM_PRIORITY+2,Color.red);}});addButton(buttonPanel,"Close",newActionListener(){publicvoidactionPerformed(ActionEventevt){System.exit(0);}});contentPane.add(buttonPanel,BorderLayout.SOUTH);}publicvoidaddButton(Containerc,Stringtitle,ActionListenerlistener){JButtonbutton=newJButton(title);//生成一个按钮。c.add(button);//加入容器中。button.addActionListener(listener);//按钮绑上action监听器。}/**主要业务方法。*/publicvoidaddBall(intpriority,Colorcolor){//生成小球(参数对象)BallPressb=newBallPress(canvas,color);//生成BallPress对象,携带、初始化//画Ball形小球,所需参数:所在容器组件,所需color--black/red.//小球加入List中。canvas.add(b);//面板canvas的ArrayList中加入BallPress对象。BallPressThreadthread=newBallPressThread(b);//生成画小球的线程类BallPressThread对象。传入BallPress对象(携带免费JAVA长代码了画球所需//容器、color参数)。thread.setPriority(priority);thread.start();//callrun(),ballstarttomove//画球线程开始。---BallPressThread的run()---小球(参数对象).move()---先移动,再画。canvas.paint---BallPressCanvas类的}}//画球的线程类。classBallPressThreadextendsThread{privateBallPressb;publicBallPressThread(BallPressaBall){b=aBall;}//画球开始。publicvoidrun(){try{for(inti=1;i自动绘制面板,且自动调paintComponent(Graphics//g)方法,---重写该方法,绘制面板(及其上组件)。//作用2)该类对象属性ArrayListballs---兼作小球(参数对象)的容器。classBallPressCanvasextendsJPanel{privateArrayListballs=newArrayList();publicvoidadd(BallPressb){balls.add(b);//向ArrayList中添加球。当按下按钮,添加多个球时,都保存在这个List中。}//重写了javax.swing.JComponent的paintComponent()方法。//paint()方法自动调用该方法。publicvoidpaintComponent(Graphicsg){super.paintComponent(g);Graphics2Dg2=(Graphics2D)g;for(inti=0;i=canvas.getWidth()){//小球右边已经到画板右边。x=canvas.getWidth()-15;dx=-dx;//开始反向运动。}if(y=canvas.getHeight()){//小球已到画板顶。y=canvas.getHeight()-15;dy=-dy;}canvas.paint(canvas.getGraphics());//画出面板对象canvas----(及其上所有组件)////.paint()方法,自动调用}}/*importjava.awt.*;importjava.awt.event.*;importjava.awt.geom.*;importjava.util.*;importjavax.swing.*;*//***单线程,小球演示搜索不到,run()方法/.start()*//*publicclassBounce{publicstaticvoidmain(String[]args){JFrameframe=newBounceFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//similarto//window//listenerframe.show();}}不懂的再问啊。。。
相关问答
Q1: 一段比较长java的代码,高手帮我解决几个问题
1.GroupLayout layout=new GroupLayout(c);
创建一个GroupLayout免费JAVA长代码的对象,同时创建时需要以一个Container的对象作为参数
2 layout.setAutoCreateContainerGaps(true);
setAutoCreateContainerGaps(boolean)是用来设置是否应该自动创建容器与触到容器边框的组件之间的间隙,参数是一个boolean值,true代表是,false代表否。
3. GroupLayout.ParallelGroup hpg2a=layout.createParallelGroup(GroupLayout.Alignment.LEADING);
ParallelGroup 是GroupLayout的一个内部类,所以要创建他的实例必须是这样的:GroupLayout.ParallelGroup
createParallelGroup(GroupLayout.Alignment alignment)方法使用 Alignment.LEADING 的对齐方式创建并返回一个 ParallelGroup,Alignment.LEADING是GroupLayout的一个field,在这里以这个作为参数。 这句话就是一个简单的语句,不能再简单里,免费JAVA长代码你看里面虽然有很多点,但其实只有一个层次就相当于 A a = b.c(o);
4. hpg2a.addComponent(cb2);
将 Component 对象作为参数添加到此 Group。就是给GroupLayout.ParallelGroup添加一个cb2组件
总结:你对api很不免费JAVA长代码了解,这些东西都是在api里面可以查到的,所以你应该把api下载下来,放在自己的桌面上随时查阅,学java 的时候api文档是必不可少的工具哦,加油免费JAVA长代码!
Q2: 求java小程序代码,500行左右。。大作业用。追加50
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess[][] = new int[11][11];
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i 11;i++)
{
for(int j = 0;j 11;j++)
{
chess[i][j] = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, 360, 360);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x 25 || x 330 + 25 ||y 25 || y 330+25)
{
return;
}
if(chess[x/30-1][y/30-1] != 0)
{
return;
}
if(Is_Black_True == true)
{
chess[x/30-1][y/30-1] = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess[x/30-1][y/30-1] = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = 30;i = 330;i += 30)
{
for(int j = 30;j = 330; j+= 30)
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j = 330;j += 30)
{
g.setColor(Color.WHITE);
g.drawLine(30, j, 330, j);
}
}
void Drawchess(Graphics g)
{
for(int i = 0;i 11;i++)
{
for(int j = 0;j 11;j++)
{
if(chess[i][j] == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
if(chess[i][j] == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;
for(i = 0;i 11;i++)//横向判断
{
for(int j = 0;j 11;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 11;i++)//竖向判断
{
for(int j = 0;j 11;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 11;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;i11;i++)
{
for(int j=0;j11;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,23, 360, 360);
setTitle("单人版五子棋");
setBounds(200, 200, 360, 383);
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长代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于找java代码的免费网站、免费JAVA长代码的信息别忘了在本站进行查找喔。





