導航:首頁 > 源碼編譯 > java最火的源碼

java最火的源碼

發布時間:2023-06-01 09:51:16

㈠ GitHub上面有哪些經典的java框架源碼

Hadoop Velocity Freemarker Ehcache Eclipse Mina Netty Hibernate MyBatis Spring Tomcat等等 實搭塌在是太多了
給你個列表 上邊列著github上所有知名java項目
https://github.com/akullpp/awesome-java
這知姿圓個就是樓上說冊沒的awesome-java

㈡ 求java小游戲源代碼

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Vector;

public class Frame extends JFrame implements Runnable {
JPanel contentPane;

JPanel jPanel1 = new JPanel();

JButton jButton1 = new JButton();

JSlider jSlider1 = new JSlider();

JLabel jLabel1 = new JLabel();

JButton jButton2 = new JButton();

JLabel jLabel2 = new JLabel();

int count = 1, rapidity = 80; // count 當前進行的個數, rapidity 游標的位置

int zhengque = 0, cuowu = 0;

int rush[] = { 10 ,20 ,30 }; //游戲每關的個數 可以自由添加.列 { 10 ,20 ,30 ,40,50}

int rush_count = 0; //記錄關數

char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; //隨機出現的數字 可以自由添加

Vector number = new Vector();

String paian = "true";

AudioClip Musci_anjian, Music_shi, Music_chenggong;

public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);

//-----------------聲音文件---------------------
Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")
.toURL());
Music_shi = Applet.newAudioClip(new File("sounds//shi.wav")
.toURL());
Music_chenggong = Applet.newAudioClip(new File(
"sounds//chenggong.wav").toURL());

//---------------------------------------
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(588, 530));
setTitle("Frame Title");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(4, 4, 573, 419));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(277, 442, 89, 31));
jButton1.setText("開始");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jSlider1.setBounds(new Rectangle(83, 448, 164, 21));
jSlider1.setMaximum(100);
jSlider1.setMinimum(1);
jSlider1.setValue(50);
jLabel1.setText("速度");
jLabel1.setBounds(new Rectangle(35, 451, 39, 18));
jButton2.setBounds(new Rectangle(408, 442, 89, 31));
jButton2.setText("結束");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jLabel2.setText("第一關:100個");
jLabel2.setBounds(new Rectangle(414, 473, 171, 21));
contentPane.add(jPanel1);
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jSlider1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
this.addKeyListener(new MyListener());
jButton1.addKeyListener(new MyListener());
jSlider1.addKeyListener(new MyListener());
jSlider1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
rapidity = jSlider1.getValue();
}
});
}

public void run() {
number.clear();
zhengque = 0;
cuowu = 0;
paian = "true";
while (count <= rush[rush_count]) {
try {
Thread t = new Thread(new Tthread());
t.start();
count += 1;
Thread.sleep(1000 + (int) (Math.random() * 2000)); // 生產下組停頓時間
// 最快1快.最慢2秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}

while (true) { // 等待最後一個字元消失
if (number.size() == 0) {
break;
}
}

if (zhengque == 0) { // 為了以後相除..如果全部正確或者錯誤就會出現錯誤. 所以..
zhengque = 1;
}
if (cuowu == 0) {
cuowu = 1;
}

if (paian.equals("true")) { // 判斷是否是自然結束
if (zhengque / cuowu >= 2) {
JOptionPane.showMessageDialog(null, "恭喜你過關了");
rush_count += 1; // 自動加1關
if (rush_count < rush.length) {
if (rapidity > 10) { // 當速度大於10的時候在-5提加速度.怕速度太快
rapidity -= 5; // 速度自動減10毫秒
jSlider1.setValue(rapidity); // 選擇位置
}
Thread t = new Thread(this);
t.start();
} else {
JOptionPane.showMessageDialog(null, "牛B...你通關了..");
rush_count = 0;
count = 0;
}
} else {
JOptionPane.showMessageDialog(null, "請再接再勵");
rush_count = 0;
count = 0;
}
} else {
rush_count = 0;
count = 0;
}
}

public void jButton1_actionPerformed(ActionEvent e) {
Thread t = new Thread(this);
t.start();
}

public void jButton2_actionPerformed(ActionEvent e) {
count = rush[rush_count] + 1;
paian = "flase";
}

class Tthread implements Runnable {
public void run() {
boolean fo = true;
int Y = 0, X = 0;
JLabel show = new JLabel();
show.setFont(new java.awt.Font("宋體", Font.PLAIN, 33));
jPanel1.add(show);
X = 10 + (int) (Math.random() * 400);
String parameter = list[(int) (Math.random() * list.length)] + "";
Bean bean = new Bean();
bean.setParameter(parameter);
bean.setShow(show);
number.add(bean);
show.setText(parameter);
while (fo) {
// ---------------------數字下移--------------------
show.setBounds(new Rectangle(X, Y += 2, 33, 33));
try {
Thread.sleep(rapidity);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Y >= 419) {
fo = false;
for (int i = number.size() - 1; i >= 0; i--) {
Bean bn = ((Bean) number.get(i));
if (parameter.equalsIgnoreCase(bn.getParameter())) {
cuowu += 1;
jLabel2.setText("正確:" + zhengque + "個,錯誤:" + cuowu
+ "個");
number.removeElementAt(i);
Music_shi.play();
break;
}
}
}
}

}
}

class MyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
String uu = e.getKeyChar() + "";
for (int i = 0; i < number.size(); i++) {
Bean bean = ((Bean) number.get(i));
if (uu.equalsIgnoreCase(bean.getParameter())) {
zhengque += 1;
number.removeElementAt(i);
bean.getShow().setVisible(false);
jLabel2.setText("正確:" + zhengque + "個,錯誤:" + cuowu + "個");
Music_chenggong.play();
break;
}
}

Musci_anjian.play();
}
}

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
Frame frame = new Frame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
}

class Frame1_jButton2_actionAdapter implements ActionListener {
private Frame adaptee;

Frame1_jButton2_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame adaptee;

Frame1_jButton1_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}

class Bean {
String parameter = null;

JLabel show = null;

public JLabel getShow() {
return show;
}

public void setShow(JLabel show) {
this.show = show;
}

public String getParameter() {
return parameter;
}

public void setParameter(String parameter) {
this.parameter = parameter;
}
}

㈢ 掃雷java源代碼

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame
extends JFrame {
JTextField text;
JLabel nowBomb, setBomb;
int BombNum, BlockNum; // 當前雷數,當前方塊數
int rightBomb, restBomb, restBlock; // 找到的地雷數,剩餘雷數,剩餘方塊數

JButton start = new JButton(" 開始 ");
JPanel MenuPamel = new JPanel();
JPanel bombPanel = new JPanel();
Bomb[][] bombButton;

JPanel c;
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}

private void jbInit() throws Exception {
c = (JPanel) getContentPane();
setTitle("掃雷");
c.setBackground(Color.WHITE);
MenuPamel.setBackground(Color.GRAY);
c.setLayout(borderLayout1);
setSize(new Dimension(600, 600));
setResizable(false);

BlockNum = 144;
BombNum = 10;
text = new JTextField("10 ", 3);
nowBomb = new JLabel("當前雷數" + ":" + BombNum);
setBomb = new JLabel("設置地雷數");
start.addActionListener(new Frame1_start_actionAdapter(this));

MenuPamel.add(setBomb);
MenuPamel.add(text);
MenuPamel.add(start);
MenuPamel.add(nowBomb);
c.add(MenuPamel, java.awt.BorderLayout.SOUTH);

bombPanel.setLayout(gridLayout1);
gridLayout1.setColumns( (int) Math.sqrt(BlockNum));
gridLayout1.setRows( (int) Math.sqrt(BlockNum));
bombButton = new Bomb[ (int) Math.sqrt(BlockNum)][ (int) Math.sqrt(BlockNum)];
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
bombButton[i][j] = new Bomb(i, j);
//bombButton[i][j].setSize(10, 10);
bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//設置字體大小

bombButton[i][j].setForeground(Color.white);
bombButton[i][j].addMouseListener(new Bomb_mouseAdapter(this));
bombButton[i][j].addActionListener(new Bomb_actionAdapter(this));
bombPanel.add(bombButton[i][j]);
}
}
c.add(bombPanel, java.awt.BorderLayout.CENTER);

startBomb();
}

/* 開始按鈕 */

public void start_actionPerformed(ActionEvent e) {
int num=Integer.parseInt(text.getText().trim());
if (num >= 5 && num < 50) {
BombNum = num;
startBomb();
}
else if (num < 5) {
JOptionPane.showMessageDialog(null, "您設置的地雷數太少了,請重設!", "錯誤",
JOptionPane.ERROR_MESSAGE);
num=10;
BombNum = num;
}
else {
JOptionPane.showMessageDialog(null, "您設置的地雷數太多了,請重設!", "錯誤",
JOptionPane.ERROR_MESSAGE);
num=10;
BombNum = num;
}
}

/* 開始,布雷 */

public void startBomb() {
nowBomb.setText("當前雷數" + ":" + BombNum);
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
bombButton[i][j].isBomb = false;
bombButton[i][j].isClicked = false;
bombButton[i][j].isRight = false;
bombButton[i][j].BombFlag = 0;
bombButton[i][j].BombRoundCount = 9;
bombButton[i][j].setEnabled(true);
bombButton[i][j].setText("");
bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//設置字體大小
bombButton[i][j].setForeground(Color.BLUE);
rightBomb = 0;
restBomb = BombNum;
restBlock = BlockNum - BombNum;
}
}

for (int i = 0; i < BombNum; ) {
int x = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1));
int y = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1));

if (bombButton[x][y].isBomb != true) {
bombButton[x][y].isBomb = true;
i++;
}
}
CountRoundBomb();
}

/* 計算方塊周圍雷數 */

public void CountRoundBomb() {
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
int count = 0;
// 當需要檢測的單元格本身無地雷的情況下,統計周圍的地雷個數
if (bombButton[i][j].isBomb != true) {
for (int x = i - 1; x < i + 2; x++) {
for (int y = j - 1; y < j + 2; y++) {
if ( (x >= 0) && (y >= 0)
&& (x < ( (int) Math.sqrt(BlockNum)))
&& (y < ( (int) Math.sqrt(BlockNum)))) {
if (bombButton[x][y].isBomb == true) {
count++;
}
}
}
}
bombButton[i][j].BombRoundCount = count;
}
}
}
}

/* 是否挖完了所有的雷 */

public void isWin() {
restBlock = BlockNum - BombNum;
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
if (bombButton[i][j].isClicked == true) {
restBlock--;
}
}
}

if (rightBomb == BombNum || restBlock == 0) {
JOptionPane.showMessageDialog(this, "您挖完了所有的雷,您勝利了!", "勝利",
JOptionPane.INFORMATION_MESSAGE);
startBomb();
}
}

/** 當選中的位置為空,則翻開周圍的地圖* */

public void isNull(Bomb ClickedButton) {
int i, j;
i = ClickedButton.num_x;
j = ClickedButton.num_y;

for (int x = i - 1; x < i + 2; x++) {
for (int y = j - 1; y < j + 2; y++) {
if ( ( (x != i) || (y != j)) && (x >= 0) && (y >= 0)
&& (x < ( (int) Math.sqrt(BlockNum)))
&& (y < ( (int) Math.sqrt(BlockNum)))) {
if (bombButton[x][y].isBomb == false
&& bombButton[x][y].isClicked == false
&& bombButton[x][y].isRight == false) {
turn(bombButton[x][y]);
}
}
}
}
}

/* 翻開 */

public void turn(Bomb ClickedButton) {
ClickedButton.setEnabled(false);
ClickedButton.isClicked = true;
if (ClickedButton.BombRoundCount > 0) {
ClickedButton.setText(ClickedButton.BombRoundCount + "");
}
else {
isNull(ClickedButton);
}
}

/* 左鍵點擊 */

public void actionPerformed(ActionEvent e) {
if ( ( (Bomb) e.getSource()).isClicked == false
&& ( (Bomb) e.getSource()).isRight == false) {
if ( ( (Bomb) e.getSource()).isBomb == false) {
turn( ( (Bomb) e.getSource()));
isWin();
}

else {
for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) {
for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) {
if (bombButton[i][j].isBomb == true) {
bombButton[i][j].setText("b");
}
}
}
( (Bomb) e.getSource()).setForeground(Color.RED);
( (Bomb) e.getSource()).setFont(new Font("", Font.BOLD, 20));
( (Bomb) e.getSource()).setText("X");
JOptionPane.showMessageDialog(this, "你踩到地雷了,按確定重來", "踩到地雷", 2);
startBomb();
}
}
}

/* 右鍵點擊 */

public void mouseClicked(MouseEvent e) {
Bomb bombSource = (Bomb) e.getSource();
boolean right = SwingUtilities.isRightMouseButton(e);

if ( (right == true) && (bombSource.isClicked == false)) {
bombSource.BombFlag = (bombSource.BombFlag + 1) % 3;
if (bombSource.BombFlag == 1) {
if (restBomb > 0) {
bombSource.setForeground(Color.RED);
bombSource.setText("F");
bombSource.isRight = true;
restBomb--;
}
else {
bombSource.BombFlag = 0;
}
}
else if (bombSource.BombFlag == 2) {
restBomb++;
bombSource.setText("Q");
bombSource.isRight = false;
}
else {
bombSource.setText("");
}

if (bombSource.isBomb == true) {
if (bombSource.BombFlag == 1) {
rightBomb++;
}
else if (bombSource.BombFlag == 2) {
rightBomb--;
}
}
nowBomb.setText("當前雷數" + ":" + restBomb);
isWin();
}
}

public static void main(String[] args) {
Frame frame = new Frame();
frame.setVisible(true);
}
}

class Frame1_start_actionAdapter
implements ActionListener {
private Frame adaptee;
Frame1_start_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.start_actionPerformed(e);
}
}

////////////////////////////
class Bomb
extends JButton {
int num_x, num_y; // 第幾號方塊
int BombRoundCount; // 周圍雷數
boolean isBomb; // 是否為雷
boolean isClicked; // 是否被點擊
int BombFlag; // 探雷標記
boolean isRight; // 是否點擊右鍵

public Bomb(int x, int y) {
num_x = x;
num_y = y;
BombFlag = 0;
BombRoundCount = 9;
isBomb = false;
isClicked = false;
isRight = false;
}
}

class Bomb_actionAdapter
implements ActionListener {
private Frame adaptee;
Bomb_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.actionPerformed(e);
}
}

class Bomb_mouseAdapter
extends MouseAdapter {
private Frame adaptee;
Bomb_mouseAdapter(Frame adaptee) {
this.adaptee = adaptee;
}

public void mouseClicked(MouseEvent e) {
adaptee.mouseClicked(e);
}
}

㈣ GitHub上面有哪些經典的java框架源碼

㈤ 求java版畫圖程序的源代碼

找到了,很久以前寫的一個簡單畫圖,呵呵~當時要求用AWT寫,很難受。

package net.miqiang.gui;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;

/**
* 簡單畫圖板程序
* 好久沒用 AWT 了,寫起來真別扭,如果用 swing 會很舒服,有空再改寫吧。
*
* @author 米強
*
*/
public class TestMain extends Frame {
// 畫板
private Palette palette = null;

// 顯示當前顏色的面板
private Panel nonceColor = null;

// 畫筆粗細
private Label drawWidth = null;

// 畫筆端點的裝飾
private Label drawCap = null;

// 選取顏色按鈕的監聽事件類
private ButtonColorAction buttonColorAction = null;

// 滑鼠進入按鈕後游標樣式的監聽事件類
private ButtonCursor buttonCursor = null;

// 畫筆樣式的監聽事件
private ButtonStrokeAction buttonStrokeAction = null;

/**
* 構造方法
*
*/
public TestMain() {
// 設置標題欄文字
super("簡易畫圖板");

// 構造一個畫圖板
palette = new Palette();

Panel pane = new Panel(new GridLayout(2, 1));

// 畫筆顏色選擇器
Panel paneColor = new Panel(new GridLayout(1, 13));

// 12 個顏色選擇按鈕
Button [] buttonColor = new Button[12];
Color [] color = {Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
// 顯示當前顏色的面板
nonceColor = new Panel();
nonceColor.setBackground(Color.black);
paneColor.add(nonceColor);
buttonColorAction = new ButtonColorAction();
buttonCursor = new ButtonCursor();
for(int i = 0; i < buttonColor.length; i++){
buttonColor[i] = new Button();
buttonColor[i].setBackground(color[i]);
buttonColor[i].addActionListener(buttonColorAction);
buttonColor[i].addMouseListener(buttonCursor);
paneColor.add(buttonColor[i]);
}
pane.add(paneColor);

// 畫筆顏色選擇器
Panel paneStroke = new Panel(new GridLayout(1, 13));

// 控制畫筆樣式
buttonStrokeAction = new ButtonStrokeAction();
Button [] buttonStroke = new Button[11];
buttonStroke[0] = new Button("1");
buttonStroke[1] = new Button("3");
buttonStroke[2] = new Button("5");
buttonStroke[3] = new Button("7");
buttonStroke[4] = new Button("9");
buttonStroke[5] = new Button("11");
buttonStroke[6] = new Button("13");
buttonStroke[7] = new Button("15");
buttonStroke[8] = new Button("17");
buttonStroke[9] = new Button("■");
buttonStroke[10] = new Button("●");
drawWidth = new Label("3", Label.CENTER);
drawCap = new Label("●", Label.CENTER);
drawWidth.setBackground(Color.lightGray);
drawCap.setBackground(Color.lightGray);
paneStroke.add(drawWidth);
for(int i = 0; i < buttonStroke.length; i++){
paneStroke.add(buttonStroke[i]);
buttonStroke[i].addMouseListener(buttonCursor);
buttonStroke[i].addActionListener(buttonStrokeAction);
if(i <= 8){
buttonStroke[i].setName("width");
}else{
buttonStroke[i].setName("cap");
}
if(i == 8){
paneStroke.add(drawCap);
}
}
pane.add(paneStroke);

// 將畫筆顏色選擇器添加到窗體中
this.add(pane, BorderLayout.NORTH);

// 將畫圖板添加到窗體中
this.add(palette);

// 添加窗口監聽,點擊關閉按鈕時退出程序
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

// 設置窗體 ICON 圖標
this.setIconImage(Toolkit.getDefaultToolkit().createImage("images/palette.png"));

// 設置窗口的大小
this.setSize(new Dimension(400, 430));
// 設置窗口位置,處於屏幕正中央
this.setLocationRelativeTo(null);
// 顯示窗口
this.setVisible(true);
}

/**
* 程序入口
*
* @param args
* 字元串數組參數
*/
public static void main(String[] args) {
new TestMain();
}

/**
* 選取顏色按鈕的監聽事件類
* @author 米強
*
*/
class ButtonColorAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
Color color_temp = ((Button)e.getSource()).getBackground();
nonceColor.setBackground(color_temp);
palette.setColor(color_temp);
}

}

/**
* 滑鼠進入按鈕變換游標樣式監聽事件類
* @author 米強
*
*/
class ButtonCursor extends MouseAdapter {

public void mouseEntered(MouseEvent e) {
((Button)e.getSource()).setCursor(new Cursor(Cursor.HAND_CURSOR));
}

public void mouseExited(MouseEvent e) {
((Button)e.getSource()).setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

}

/**
* 設置畫筆的監聽事件類
* @author 米強
*
*/
class ButtonStrokeAction implements ActionListener {

public void actionPerformed(ActionEvent e) {
Button button_temp = (Button) e.getSource();
String name = button_temp.getName();
if(name.equalsIgnoreCase("width")){
drawWidth.setText(button_temp.getLabel());
palette.setStroke(Float.parseFloat(button_temp.getLabel()));
}else if(name.equalsIgnoreCase("cap")){
drawCap.setText(button_temp.getLabel());
if(button_temp.getLabel().equals("■")){
palette.setStroke(BasicStroke.CAP_SQUARE);
}else if(button_temp.getLabel().equals("●")){
palette.setStroke(BasicStroke.CAP_ROUND);
}
}
}

}

}

/**
* 畫板類
*
* @author 米強
*
*/
class Palette extends Panel implements MouseListener, MouseMotionListener {
// 滑鼠 X 坐標的位置
private int mouseX = 0;

// 上一次 X 坐標位置
private int oldMouseX = 0;

// 滑鼠 Y 坐標的位置
private int mouseY = 0;

// 上一次 Y 坐標位置
private int oldMouseY = 0;

// 畫圖顏色
private Color color = null;

// 畫筆樣式
private BasicStroke stroke = null;

// 緩存圖形
private BufferedImage image = null;

/**
* 構造一個畫板類
*
*/
public Palette() {
this.addMouseListener(this);
this.addMouseMotionListener(this);
// 默認黑色畫筆
color = new Color(0, 0, 0);
// 設置默認畫筆樣式
stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
// 建立 1280 * 1024 的 RGB 緩存圖象
image = new BufferedImage(1280, 1024, BufferedImage.TYPE_INT_RGB);
// 設置顏色
image.getGraphics().setColor(Color.white);
// 畫背景
image.getGraphics().fillRect(0, 0, 1280, 1024);
}

/**
* 重寫 paint 繪圖方法
*/
public void paint(Graphics g) {
super.paint(g);

// 轉換為 Graphics2D
Graphics2D g2d = (Graphics2D) g;

// 獲取緩存圖形 Graphics2D
Graphics2D bg = image.createGraphics();

// 圖形抗鋸齒
bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

// 設置繪圖顏色
bg.setColor(color);

// 設置畫筆樣式
bg.setStroke(stroke);

// 畫線,從上一個點到新的點
bg.drawLine(oldMouseX, oldMouseY, mouseX, mouseY);

// 將緩存中的圖形畫到畫板上
g2d.drawImage(image, 0, 0, this);
}

/**
* 重寫 update 方法
*/
public void update(Graphics g) {
this.paint(g);
}

/**
* @return stroke
*/
public BasicStroke getStroke() {
return stroke;
}

/**
* @param stroke 要設置的 stroke
*/
public void setStroke(BasicStroke stroke) {
this.stroke = stroke;
}

/**
* 設置畫筆粗細
* @param width
*/
public void setStroke(float width) {
this.stroke = new BasicStroke(width, stroke.getEndCap(), stroke.getLineJoin());
}

/**
* 設置畫筆端點的裝飾
* @param cap 參考 java.awt.BasicStroke 類靜態欄位
*/
public void setStroke(int cap) {
this.stroke = new BasicStroke(stroke.getLineWidth(), cap, stroke.getLineJoin());
}

/**
* @return color
*/
public Color getColor() {
return color;
}

/**
* @param color 要設置的 color
*/
public void setColor(Color color) {
this.color = color;
}

public void mouseClicked(MouseEvent mouseEvent) {
}

/**
* 滑鼠按下
*/
public void mousePressed(MouseEvent mouseEvent) {
this.oldMouseX = this.mouseX = mouseEvent.getX();
this.oldMouseY = this.mouseY = mouseEvent.getY();
repaint();
}

public void mouseReleased(MouseEvent mouseEvent) {
}

/**
* 滑鼠進入棋盤
*/
public void mouseEntered(MouseEvent mouseEvent) {
this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}

/**
* 滑鼠退出棋盤
*/
public void mouseExited(MouseEvent mouseEvent) {
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

/**
* 滑鼠拖動
*/
public void mouseDragged(MouseEvent mouseEvent) {
this.oldMouseX = this.mouseX;
this.oldMouseY = this.mouseY;
this.mouseX = mouseEvent.getX();
this.mouseY = mouseEvent.getY();
repaint();
}

public void mouseMoved(MouseEvent mouseEvent) {
}

}

㈥ java 目前市面上比較火的框架有哪些

Java 始終排在第一位,這使它成為有史以來最著名的軟體編程語言之一。及時的更新和新版本發布使它成為一種充滿活力的、有競爭力的編程語言。

2020年最常用的java框架

十大常用框架:

㈦ 求JAVA源代碼 ~~~~!!!!!!

我給你一個計算器的源代碼,這個好講。自己前幾天寫的,已經被網路收錄了。
import java.awt.Button; import java.awt.Color; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.TextField; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class Calculator extends WindowAdapter implements MouseListener { private String first; private String second; private String operator; private Button zero = new Button("0"); private Button one = new Button("1"); private Button two = new Button("2"); private Button three = new Button("3"); private Button four = new Button("4"謹升); private Button five = new Button("5"); private Button six = new Button("6"); private Button seven = new Button("7"); private Button eight = new Button("8"); private Button nine = new Button("9"); private Button decimal = new Button("."); private Button equal = new Button("="); private Button add = new Button("+"); private Button sub = new Button("-"); private Button mul = new Button("*"); private Button div = new Button("/"); private TextField input = new TextField(); private Button CE = new Button("CE"); private Button DEL = new Button("Del"); 旦晌旦public static void main(String[] args) { new Calculator(); } public Calculator(){ Frame f = new Frame("Calculator"); f.add("North", input); Panel keys = new Panel(); f.add(keys, "Center"); keys.setLayout(new GridLayout(4, 4)); keys.add(seven); keys.add(eight); keys.add(nine); keys.add(add); keys.add(four); keys.add(five); keys.add(six); keys.add(sub); keys.add(one); keys.add(two); keys.add(three); keys.add(mul); keys.add(zero); 模擾keys.add(decimal); keys.add(equal); keys.add(div); zero.addMouseListener(this); one.addMouseListener(this); two.addMouseListener(this); three.addMouseListener(this); four.addMouseListener(this); five.addMouseListener(this); six.addMouseListener(this); seven.addMouseListener(this); eight.addMouseListener(this); nine.addMouseListener(this); add.addMouseListener(this); sub.addMouseListener(this); div.addMouseListener(this); mul.addMouseListener(this); equal.addMouseListener(this); decimal.addMouseListener(this); Panel addtionalPanel = new Panel(); addtionalPanel.setLayout(new GridLayout(1, 2)); addtionalPanel.add(CE); addtionalPanel.add(DEL); CE.setBackground(Color.green); DEL.setBackground(Color.cyan); CE.addMouseListener(this); DEL.addMouseListener(this); f.add("South", addtionalPanel); f.addWindowListener(this); f.setVisible(true); f.setLocation(200, 300); f.setSize(200, 200); } public void windowClosing(WindowEvent e) { System.exit(0); } public void mouseClicked(MouseEvent e) { Button btn = (Button) e.getSource(); String key = btn.getActionCommand().trim(); if(btn == one || btn == two || btn == three || btn == zero || btn == four || btn == five || btn == six || btn == seven || btn == eight || btn == nine){ if(isBlank(operator)){ if(isBlank(first)){ first = key; }else{ first += key; } input.setText(first); }else{ if(isBlank(second)){ second = key; }else{ second += key; } input.setText(second); } }else if(btn == decimal){ if(isBlank(operator)){ if(isBlank(first)){ first = "0."; input.setText(first); }else{ if(first.indexOf(".") == -1){ first += "."; input.setText(first); } } }else{ if(isBlank(second)){ second = "0."; input.setText(second); }else{ if(second.indexOf(".") == -1){ second += "."; input.setText(second); } } } }else if(btn == equal){ if(!isBlank(second) && !isBlank(first) && !isBlank(operator)){ double result = 0.0D; if(operator.equals("+")){ result = Double.parseDouble(first) + Double.parseDouble(second); }else if(operator.equals("-")){ result = Double.parseDouble(first) - Double.parseDouble(second); }else if(operator.equals("*")){ result = Double.parseDouble(first) * Double.parseDouble(second); }else if(operator.equals("/")){ result = Double.parseDouble(first) / Double.parseDouble(second); } int value = (int)Math.round(result); if(value == result){ input.setText(String.valueOf(value)); }else{ input.setText(String.valueOf(result)); } first = String.valueOf(result); second = null; operator = null; } }else if(btn == add || btn == sub || btn == div || btn == mul){ if(!isBlank(first)){ if(!isBlank(operator) && !isBlank(second)){ if(operator.equals("+")){ first = String.valueOf(Double.parseDouble(first) + Double.parseDouble(second)); }else if(operator.equals("-")){ first = String.valueOf(Double.parseDouble(first) - Double.parseDouble(second)); }else if(operator.equals("*")){ first = String.valueOf(Double.parseDouble(first) * Double.parseDouble(second)); }else if(operator.equals("/")){ first = String.valueOf(Double.parseDouble(first) / Double.parseDouble(second)); } second = null; } operator = key; } }else if(btn == CE){ first = null; second = null; operator = null; input.setText(null); }else if(btn == DEL){ if(isBlank(operator)){ if(!isBlank(first)){ first = first.substring(0, first.length() -1); input.setText(first); } }else{ if(!isBlank(second)){ second = second.substring(0, second.length() -1); input.setText(second); } } } } private boolean isBlank(String str){ return str == null || str.trim().equals(""); } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }

㈧ java 聊天室 源代碼

最簡單的聊天室

㈨ 求JAVA源代碼

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class GradeStatistic {

public static void main(String[] args) {

GradeStatistic gs = new GradeStatistic();

List<Mark> list = new ArrayList<Mark>();

float sum = 0;

while(true){

Scanner sc = new Scanner(System.in);

System.out.print("Please input student name: ");
String name = sc.nextLine();

if(name.equals("end")){
break;
}

System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;

list.add(gs.new Mark(name, score));

}

float max = list.get(0).getScore();
float min = list.get(0).getScore();

for(Mark mark: list){
if(max < mark.getScore()){
max = mark.getScore();
}

if(min > mark.getScore()){
min = mark.getScore();
}

}

float average = sum / list.size();

System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}

private class Mark{
private String name;
private float score;

public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0

㈩ 求java rpg小游戲源代碼 最好是文字rpg 不需要很復雜 只是交作業用

連連看的小源碼

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

閱讀全文

與java最火的源碼相關的資料

熱點內容
android智能家居藍牙 瀏覽:646
pt螺紋編程 瀏覽:451
手機電音app哪個好 瀏覽:749
checksum命令 瀏覽:637
java創建xml文件 瀏覽:170
算命源碼國際版 瀏覽:283
三菱模塊化編程 瀏覽:718
控制項讀取文件源碼 瀏覽:445
文件夾側面目錄標簽怎麼製作 瀏覽:232
做程序員學什麼 瀏覽:320
pdfeditor教程 瀏覽:880
fortran把文件放入文件夾 瀏覽:709
程序員1年經驗不敢投簡歷 瀏覽:481
如何看電腦的源碼 瀏覽:897
找工作app軟體哪個好 瀏覽:96
信息管理網站源碼 瀏覽:439
小說app哪個好免費 瀏覽:224
域名在線加密 瀏覽:146
軟體編程西安交大 瀏覽:453
是不是串貨的奶粉查不到溯源碼的 瀏覽:825