導航:首頁 > 源碼編譯 > java小程序直播系統源碼

java小程序直播系統源碼

發布時間:2022-07-25 19:45:36

Ⅰ 求一java編寫的小程序源碼,能夠運行會追加!

package org.nightrunner..;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class QuestionOne {
/**
* 一組序列由AGCT四個字元組成,例如:AGAAGGAAAAAAGAGGAAGAGGAGAT
* ,要求編一小程序
* 例如:輸入一個字元串AAAG,從頭開始如果這個字元串在上面的序列,輸出:查找成功,並記錄位置,沒有上面字元串則輸出:無法找到,退出
*
* @param args
*/
public static void main(String[] args) {
String data = "AGAAGGAAAAAAGAGGAAGAGGAGAT";
System.out.println("請輸入一個字元串,回車結束");
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String line = null;
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
int pos = data.indexOf(line);
if (pos == -1) {
System.out.println("無法找到 退出");
} else {
System.out.println("找到了,在第" + (pos + 1) + "個字元");
}
}
}

Ⅱ 810分求一個JAVA 小程序的源碼

...這個完全可以逆向匯編到這球來了。。真浪費積分 如果沒人回答你呢。等於浪費額、
告訴你以後球問題的時候最好是5分然後對了給人家 加分。你這樣浪費況且人家不返還給你 的積分的。。。
去找程序然後反匯編自己去看就好了

Ⅲ java的一個小程序,求源碼

你要懶得寫的話,把數組轉成list,我記得list有個現成的sort方法,直接給你排好序了,輸出最後一個就行

Ⅳ java 小程序源代碼

求素數,比較經典的,下面是代碼及注釋
================================================
public
class
Sushu
{
/**
*
判斷一個數是不是素數
*
@param
a
被判斷的數
*
@return
是素數返回真
*/
public
boolean
isSuhu(int
a){
boolean
isSushu=true;
//根據素數的性質判斷一個數是否為素數
for(int
i=2;i<a;i++){
if(a%i==0){
isSushu=false;
break;
}
}
return
isSushu;
}
/**
*
判斷連續若干個數中那些是素數
*
@param
start
起始數
*
@param
end
終止數
*/
public
void
selectSushu(int
start,int
end){
//判斷一串數中那些為素數,並將結果列印出來
for(int
i=start;i<=end;i++){
if(isSuhu(i)){
System.out.println(i);
}
}
}
public
static
void
main(String
[]args){
//定義起始位置和終止位置
int
start=1;
int
end=100;
//聲明變數
Sushu
s=new
Sushu();
//調用方法
s.selectSushu(start,
end);
}
}

Ⅳ 求java小程序源代碼 在線等 急急急!!!

下面是俄羅斯方塊游戲源代碼
還沒完,這代碼太長了,我用我另一個號再粘上
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;
/**
* 游戲主類,繼承自JFrame類,負責游戲的全局控制。
* 內含
* 1, 一個GameCanvas畫布類的實例引用,
* 2, 一個保存當前活動塊(ErsBlock)實例的引用,
* 3, 一個保存當前控制面板(ControlPanel)實例的引用;*/
public class ErsBlocksGame extends JFrame {
/**
* 每填滿一行計多少分*/
public final static int PER_LINE_SCORE = 100;
/**
* 積多少分以後能升級*/
public final static int PER_LEVEL_SCORE = PER_LINE_SCORE * 20;
/**
* 最大級數是10級*/
public final static int MAX_LEVEL = 10;
/**
* 默認級數是5*/
public final static int DEFAULT_LEVEL = 5;

private GameCanvas canvas;
private ErsBlock block;
private boolean playing = false;
private ControlPanel ctrlPanel;

private JMenuBar bar = new JMenuBar();
private JMenu
mGame = new JMenu("游戲設置"),
mControl = new JMenu("游戲控制"),
mWindowStyle = new JMenu("窗口風格");
private JMenuItem
miNewGame = new JMenuItem("新游戲"),
miSetBlockColor = new JMenuItem("設置顏色 ..."),
miSetBackColor = new JMenuItem("設置底色 ..."),
miTurnHarder = new JMenuItem("提升等級"),
miTurnEasier = new JMenuItem("調底等級"),
miExit = new JMenuItem("退出"),

miPlay = new JMenuItem("開始游戲"),
miPause = new JMenuItem("暫停"),
miResume = new JMenuItem("繼續");

private JCheckBoxMenuItem
miAsWindows = new JCheckBoxMenuItem("風格1"),
miAsMotif = new JCheckBoxMenuItem("風格2"),
miAsMetal = new JCheckBoxMenuItem("風格3", true);

/**
* 主游戲類的構造函數
* @param title String,窗口標題*/
public ErsBlocksGame(String title) {
super(title);
//this.setTitle("lskdf");
setSize(315, 392);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
//獲得屏幕的大小

setLocation((scrSize.width - getSize().width) / 2,
(scrSize.height - getSize().height) / 2);

createMenu();

Container container = getContentPane();
container.setLayout(new BorderLayout(6, 0));

canvas = new GameCanvas(20, 12);
ctrlPanel = new ControlPanel(this);

container.add(canvas, BorderLayout.CENTER);
container.add(ctrlPanel, BorderLayout.EAST);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
JOptionPane about=new JOptionPane();
stopGame();
System.exit(0);
}
});
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
canvas.fanning();
}
});
show();
canvas.fanning();
}
// 游戲「復位」
public void reset() {
ctrlPanel.reset();
canvas.reset();
}
/**
* 判斷游戲是否還在進行
* @return boolean, true-還在運行,false-已經停止*/
public boolean isPlaying() {
return playing;
}
/**
* 得到當前活動的塊
* @return ErsBlock, 當前活動塊的引用*/
public ErsBlock getCurBlock() {
return block;
}
/**
* 得到當前畫布
* @return GameCanvas, 當前畫布的引用 */
public GameCanvas getCanvas() {
return canvas;
}

/**
* 開始游戲*/
public void playGame() {
play();
ctrlPanel.setPlayButtonEnable(false);
miPlay.setEnabled(false);
ctrlPanel.requestFocus();
}
/**
* 游戲暫停*/
public void pauseGame() {
if (block != null) block.pauseMove();
ctrlPanel.setPauseButtonLabel(false);
miPause.setEnabled(false);
miResume.setEnabled(true);
}
/**
* 讓暫停中的游戲繼續*/
public void resumeGame() {
if (block != null) block.resumeMove();
ctrlPanel.setPauseButtonLabel(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.requestFocus();
}
/**
* 用戶停止游戲 */
public void stopGame() {
playing = false;
if (block != null) block.stopMove();
miPlay.setEnabled(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.setPlayButtonEnable(true);
ctrlPanel.setPauseButtonLabel(true);
}
/**
* 得到當前游戲者設置的游戲難度
* @return int, 游戲難度1-MAX_LEVEL*/
public int getLevel() {
return ctrlPanel.getLevel();
}
/**
* 讓用戶設置游戲難度
* @param level int, 游戲難度1-MAX_LEVEL*/
public void setLevel(int level) {
if (level < 11 && level > 0) ctrlPanel.setLevel(level);
}
/**
* 得到游戲積分
* @return int, 積分。*/
public int getScore() {
if (canvas != null) return canvas.getScore();
return 0;
}
/**
* 得到自上次升級以來的游戲積分,升級以後,此積分清零
* @return int, 積分。*/
public int getScoreForLevelUpdate() {
if (canvas != null) return canvas.getScoreForLevelUpdate();
return 0;
}
/**
* 當分數累計到一定的數量時,升一次級
* @return boolean, ture-update successufl, false-update fail
*/
public boolean levelUpdate() {
int curLevel = getLevel();
if (curLevel < MAX_LEVEL) {
setLevel(curLevel + 1);
canvas.resetScoreForLevelUpdate();
return true;
}
return false;
}
/**
* 游戲開始*/
private void play() {
reset();
playing = true;
Thread thread = new Thread(new Game());
thread.start();
}

/**
* 報告游戲結束了*/
private void reportGameOver() {
JOptionPane.showMessageDialog(this, "游戲結束!");
}
/**
* 建立並設置窗口菜單 */
private void createMenu() {
bar.add(mGame);
bar.add(mControl);
bar.add(mWindowStyle);

mGame.add(miNewGame);
mGame.addSeparator();
mGame.add(miSetBlockColor);
mGame.add(miSetBackColor);
mGame.addSeparator();
mGame.add(miTurnHarder);
mGame.add(miTurnEasier);
mGame.addSeparator();
mGame.add(miExit);

mControl.add(miPlay);
mControl.add(miPause);
mControl.add(miResume);

mWindowStyle.add(miAsWindows);
mWindowStyle.add(miAsMotif);
mWindowStyle.add(miAsMetal);

setJMenuBar(bar);

miPause.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK));
miResume.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));

miNewGame.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
stopGame();
reset();
setLevel(DEFAULT_LEVEL);
}
});
miSetBlockColor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newFrontColor =
JColorChooser.showDialog(ErsBlocksGame.this,
"設置積木顏色", canvas.getBlockColor());
if (newFrontColor != null)
canvas.setBlockColor(newFrontColor);
}
});
miSetBackColor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newBackColor =
JColorChooser.showDialog(ErsBlocksGame.this,
"設置底版顏色", canvas.getBackgroundColor());
if (newBackColor != null)
canvas.setBackgroundColor(newBackColor);
}
});
miTurnHarder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel < MAX_LEVEL) setLevel(curLevel + 1);
}
});
miTurnEasier.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel > 1) setLevel(curLevel - 1);
}
});
miExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});
miPlay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
playGame();
}
});
miPause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
pauseGame();
}
});
miResume.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
resumeGame();
}
});

miAsWindows.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(true);
miAsMetal.setState(false);
miAsMotif.setState(false);
}
});
miAsMotif.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(false);
miAsMetal.setState(false);
miAsMotif.setState(true);
}
});
miAsMetal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(false);
miAsMetal.setState(true);
miAsMotif.setState(false);
}
});
}
/**
* 根據字串設置窗口外觀
* @param plaf String, 窗口外觀的描述
*/
private void setWindowStyle(String plaf) {
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
}
}
/**
* 一輪游戲過程,實現了Runnable介面
* 一輪游戲是一個大循環,在這個循環中,每隔100毫秒,
* 檢查游戲中的當前塊是否已經到底了,如果沒有,
* 就繼續等待。如果到底了,就看有沒有全填滿的行,
* 如果有就刪除它,並為游戲者加分,同時隨機產生一個
* 新的當前塊,讓它自動下落。
* 當新產生一個塊時,先檢查畫布最頂上的一行是否已經
* 被佔了,如果是,可以判斷Game Over了。*/
private class Game implements Runnable {
public void run() {
//產生新方快
int col = (int) (Math.random() * (canvas.getCols() - 3)),
style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];
while (playing) {
if (block != null) { //第一次循環時,block為空
if (block.isAlive()) {
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
continue;
}
}
checkFullLine(); //檢查是否有全填滿的行
if (isGameOver()) { //檢查游戲是否應該結束了
miPlay.setEnabled(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.setPlayButtonEnable(true);
ctrlPanel.setPauseButtonLabel(true);

reportGameOver();
return;
}
block = new ErsBlock(style, -1, col, getLevel(), canvas);
block.start();

col = (int) (Math.random() * (canvas.getCols() - 3));
style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];

ctrlPanel.setTipStyle(style);
}
}
/**
* 檢查畫布中是否有全填滿的行,如果有就刪除之*/
public void checkFullLine() {
for (int i = 0; i < canvas.getRows(); i++) {
int row = -1;
boolean fullLineColorBox = true;
for (int j = 0; j < canvas.getCols(); j++) {
if (!canvas.getBox(i, j).isColorBox()) {
fullLineColorBox = false;
break;
}
}
if (fullLineColorBox) {
row = i--;
canvas.removeLine(row);
}
}
}

/**
* 根據最頂行是否被占,判斷游戲是否已經結束了。
* @return boolean, true-游戲結束了,false-游戲未結束*/
private boolean isGameOver() {
for (int i = 0; i < canvas.getCols(); i++) {
ErsBox box = canvas.getBox(0, i);
if (box.isColorBox()) return true;
}
return false;
}
}

Ⅵ 【求助】哪位朋友提供個Java小程序的源代碼謝謝!

import java.applet.Applet;
import java.awt.*;
import java.io.*;
import java.net.*;

public class TicTacToeclient extends Applet implements Runnable
{//class1
TextField id;
Panel boardpanel, panel2;
Square board[][],currentsquare;
Socket connection;
DataInputStream input;
DataOutputStream output;
Thread outputThread;
char mymark;
TextArea display;
public void init()
{
setLayout(new BorderLayout());
display=new TextArea(4,30);
display.setEditable(false);
add("South",display);
boardpanel=new Panel();
boardpanel.setBackground(Color.cyan);
boardpanel.setLayout(new GridLayout(3,3,0,0));
board=new Square[3][3];
for(int row=0; row<board.length; row++)
for(int col=0; col<board[row].length; col++)
{
board[row][col]=new Square();
repaint();
boardpanel.add(board[row][col]);
}
id=new TextField();
id.setEditable(false);
add("North",id);
panel2=new Panel();
panel2.add(boardpanel);
add("Center",panel2);
}
//////////end
public void start()
{
try{
connection=new Socket(InetAddress.getLocalHost(),5000);
input=new DataInputStream(connection.getInputStream());
output=new DataOutputStream(connection.getOutputStream());
}
catch(IOException e){
//e.printStackTrace();
}
outputThread=new Thread(this);
outputThread.start();
}
//////////end
public boolean mouseUP(Event e, int x, int y)
{
for( int row=0; row<board.length; row++)
{
for(int col=0; col<board[row].length; col++)
try{
if(e.target==board[row][col])
{
currentsquare=board[row][col];
output.writeInt(row*3+col);
}
}
catch(IOException ie){
//ie.printStackTrace();
}
}
return true;
}
//////////end
public void run()
{
try{
mymark=input.readChar();
id.setText("歡迎您玩家\""+mymark+"\"");
}
catch(IOException e){
e.printStackTrace();
}
while(true)
{
try{
String s=input.readUTF();
processMessage(s);
}
catch(IOException e){
//e.printStackTrace();
}
}
}
//////////end
public void processMessage(String s)
{
if(s.equals("Valid move"))
{
display.appendText("Valid move,please wait\n");
currentsquare.setMark(mymark);
currentsquare.repaint();
}
else if(s.equals("Invalid move,tryagain"))
{
display.appendText(s+"\n");
}
else if(s.equals("Opponent moved"))
{
try{
int loc=input.readInt();
done:
for(int row=0; row<board.length; row++)
for(int col=0; col<board[row].length; col++)
if(row*3+col==loc)
{
board[row][col].setMark(mymark=='x' ? 'o':'x');
board[row][col].repaint();
break done;
}
display.appendText("Opponent moved.Yourturn\n");
}
catch(IOException e){
e.printStackTrace();
}
}
else
{
display.appendText(s+"\n");
}
}

}//class1.end
//////////////////////////////////////
class Square extends Canvas
{//class2
char mark;
public Square()
{
resize(30,30);
}
//////////end
public void setMark(char c)
{
mark=c;
}
//////////end
public void paint(Graphics g)
{
g.drawRect(0,0,29,29);
g.drawString(String.valueOf(mark),11,20);
}

}//class2.end
//<applet code="TicTacToeclient.class" width=275 height=300></applet>
伺服器端:
import java.awt.*;
import java.net.*;
import java.io.*;
public class TicTacToeServer extends Frame
{//class1
private byte board[];
private boolean xMove;
private TextArea output;
private Player players[];
private ServerSocket server;
private int numberofplayers;
private int currentplayer;
public TicTacToeServer()
{
super("三子棋伺服器");
board=new byte[9];
xMove=true;
players=new Player[2];
currentplayer=0;
try{
server=new ServerSocket(5000,2);
}
catch(IOException e){
// e.printStackrace();
System.exit(1);
}

output=new TextArea();
output.setBackground(Color.yellow);
add("Center",output);
resize(300,300);
show();
Toolkit tp=Toolkit.getDefaultToolkit();
Image logo=tp.getImage("1.gif");
setIconImage(logo);
setResizable(false);
}
//////////end
public void execute()
{
for(int i=0; i<players.length; i++)
{
try{
players[i]=new Player(server.accept(), this, i);
players[i].start();
++numberofplayers;
}
catch(IOException e){
//e.printStackrace();
System.exit(1);
}
}
}
//////////end
public int getNumberOfplayers()
{
return numberofplayers;
}
//////////end
public void display(String s)
{
output.appendText(s+"\n");
}
/////////end
public boolean validMove(int loc,int player)
{
boolean moveDone=false;
while(player!=currentplayer)
{
try{
wait();
}
catch(InterruptedException e){//not
}
}
if(isOccupied(loc))
{
board[loc]=(byte)(currentplayer==0 ? 'x' : 'o');
currentplayer=++currentplayer%2;
players[currentplayer].otherplayerMoved(loc);
notify();
return true;
}
else
return false;
}
//////////end
public boolean isOccupied(int loc)
{
if(board[loc]=='x'||board[loc]=='o')
return true;
else
return false;
}
//////////end
public boolean handleEvent(Event event)
{
if(event.id==Event.WINDOW_DESTROY)
{
hide();
dispose();
for(int i=0; i<players.length; i++)
players[i].stop();
System.exit(0);

}
return super.handleEvent(event);
}
//////////end
public boolean gameOver()
{
return false;
}
//////////end
public static void main(String args[])
{
TicTacToeServer game=new TicTacToeServer();
game.execute();
}
}//class1.end
////////////////////////////////////////////////next.class
class Player extends Thread
{//class2
Socket connection;
DataInputStream input;
DataOutputStream output;
TicTacToeServer control;
int number;
char mark;
public Player(Socket s, TicTacToeServer t,int num)
{
mark=(num==0 ? 'x' : 'o');
connection=s;
try{
input=new DataInputStream(connection.getInputStream());
output=new DataOutputStream(connection.getOutputStream());
}
catch(IOException e){
//e.printStackTrale();
System.exit(1);
}
control=t;
number=num;
}
//////////end
public void otherplayerMoved(int loc)
{
try{
output.writeUTF("Opponet moved");
output.writeInt(loc);
}
catch(IOException e){//not
}
}
//////////end
public void run()
{
boolean done=false;
try{
control.display("玩家"+(number==0 ? 'x' : 'o')+"以登陸!");
output.writeChar(mark);
output.writeUTF("玩家"+(number==0 ? "x 以登陸!\n" : "o 以登陸,請等待!\n"));
if(control.getNumberOfplayers()<2)
{
output.writeUTF("請您等待另一個玩家登陸!");
while(control.getNumberOfplayers()<2);
output.writeUTF("另一個玩家已經登陸!現在您可以走棋了!");
}
while(!done)
{
int location=input.readInt();
if(control.validMove(location,number))
{
control.display("loc"+location);
output.writeUTF("Valic move.");
}
else
output.writeUTF("INvalid move,tryagain");
if(control.gameOver())
{
done=true;
}
connection.close();
}

}
catch(IOException e){
e.printStackTrace();
System.exit(1);
}
}
}//class.end

Ⅶ 求一套java開發PC端直播平台網站的源碼

https://github.com/daniulive/SmarterStreaming
國內外為數不多不依賴開源框
架、不依賴CDN實現秒開、公網毫秒級延遲、跨平台(windows/android/iOS)rtmp推流、rtmp/rtsp直播播放利
器"SmarterStreaming",系daniulive(大牛直播)出品的跨平台視頻採集、直播SDK(支持rtmp推流/rtmp播放
/rtsp播放,如windows推流(windows pusher)/android推流(android pusher)/iOS推流(iOS
pusher)/windows播放器(windows player)/android播放器(android player)/iOS播放器(iOS
player)),也許是最靠譜的視頻直播推流、播放SDK之一,助您輕松實現類似於花椒、映客、斗魚手機直播推送與播放。

Ⅷ java小程序源代碼,簡單點的,100多行,誰有啊

// 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,150000, 260000, 230000,
140000, 290000, 150000};
// 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( 10, 20, 340, 200 );
windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
windowJPanel.setLayout( null );
contentPane.add( windowJPanel );

// set up oneIconJLabel
oneIconJLabel = new JLabel();
oneIconJLabel.setBounds( 10, 20, 100, 65 );
oneIconJLabel.setIcon( new ImageIcon( "images/阿斯頓馬丁.jpg" ) );
windowJPanel.add( oneIconJLabel );

// set up oneJLabel
oneJLabel = new JLabel();
oneJLabel.setBounds( 10, 60, 100, 70 );
oneJLabel.setText( "阿斯頓馬丁" );
oneJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( oneJLabel );

// set up twoIconJLabel
twoIconJLabel = new JLabel();
twoIconJLabel.setBounds( 120, 20, 100, 65 );
twoIconJLabel.setIcon( new ImageIcon( "images/美洲虎.jpg" ) );
windowJPanel.add( twoIconJLabel );

// set up twoJLabel
twoJLabel = new JLabel();
twoJLabel.setBounds( 110, 60, 100, 70 );
twoJLabel.setText( "美洲虎" );
twoJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( twoJLabel );

// set up threeIconJLabel
threeIconJLabel = new JLabel();
threeIconJLabel.setBounds( 230, 20, 100, 65 );
threeIconJLabel.setIcon( new ImageIcon(
"images/凱迪拉克.jpg" ) );
windowJPanel.add( threeIconJLabel );

// set up threeJLabel
threeJLabel = new JLabel();
threeJLabel.setBounds( 230, 60, 100, 70);
threeJLabel.setText( "凱迪拉克" );
threeJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( threeJLabel );

// set up fourIconJLabel
fourIconJLabel = new JLabel();
fourIconJLabel.setBounds( 10, 100, 100, 65 );
fourIconJLabel.setIcon( new ImageIcon( "images/羅孚.jpg" ) );
windowJPanel.add( fourIconJLabel );

// set up fourJLabel
fourJLabel = new JLabel();
fourJLabel.setBounds( 10, 150, 50, 70 );
fourJLabel.setText( "羅孚" );
fourJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fourJLabel );

// set up fiveIconJLabel
fiveIconJLabel = new JLabel();
fiveIconJLabel.setBounds( 120, 100, 100, 65 );
fiveIconJLabel.setIcon( new ImageIcon(
"images/勞斯萊斯.jpg" ) );
windowJPanel.add( fiveIconJLabel );

// set up fiveJLabel
fiveJLabel = new JLabel();
fiveJLabel.setBounds( 110, 150, 100, 70 );
fiveJLabel.setText( "勞斯萊斯" );
fiveJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fiveJLabel );

// set up sixIconJLabel
sixIconJLabel = new JLabel();
sixIconJLabel.setBounds( 230, 100, 100, 65 );
sixIconJLabel.setIcon( new ImageIcon( "images/別克.jpg" ) );
windowJPanel.add( sixIconJLabel );

// set up sixJLabel
sixJLabel = new JLabel();
sixJLabel.setBounds( 230, 150, 100, 70 );
sixJLabel.setText( "別克" );
sixJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( sixJLabel );

// set up enterJButton
enterJButton = new JButton();
enterJButton.setBounds( 390, 160, 135, 30 );
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( 390, 200, 135, 30 );
clearJButton.setText( "Clear" );

contentPane.add( clearJButton );

// set up inputJLabel

inputJLabel = new JLabel();
inputJLabel.setBounds( 390, 25, 135, 25 );
inputJLabel.setText( "Please make selection:" );
contentPane.add( inputJLabel );

selectCountryJComboBox = new JComboBox( cars );
selectCountryJComboBox.setBounds( 390, 50, 135, 21 );
selectCountryJComboBox.setMaximumRowCount( 3 );
contentPane.add( selectCountryJComboBox );
// set up inputJTextField

inputJLabel2 = new JLabel();
inputJLabel2.setBounds( 390, 80, 150, 20 );
inputJLabel2.setText( "Input the Numble:" );
contentPane.add( inputJLabel2 );

// set up inputJTextField
inputJTextField2 = new JTextField();
inputJTextField2.setBounds( 390, 100, 135, 25 );
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( 10, 237,515, 70 );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( 550, 360 ); // 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/100;
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小程序的源代碼,要求如下

大概是這個樣子。
------------------------------------------------------------------------------------------
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DateCheck extends JFrame implements ActionListener {
private boolean isOval = true;
public DateCheck() {
setSize(567, 419);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Oval");
btnNewButton.addActionListener(this);
btnNewButton.setBounds(80, 10, 93, 23);
getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("Rect");
btnNewButton_1.setBounds(203, 10, 93, 23);
btnNewButton_1.addActionListener(this);
getContentPane().add(btnNewButton_1);
JPanel panel = new MyPanel();
panel.setBounds(12, 47, 537, 337);
getContentPane().add(panel);
new Timer().schele(new MyTimesk(), new Date(), 100);
setVisible(true);
}
public static void main(String[] args) {
new DateCheck();
}
public void actionPerformed(ActionEvent event) {
isOval = "Oval".equals(event.getActionCommand());
System.out.println(isOval);
}
class MyPanel extends JPanel implements MouseListener {
Point point1 = null;
Point point2 = null;
// protected void paintComponent(Graphics g) {
// super.paintComponent(g);
//
// }
int click = 0;
public MyPanel() {
addMouseListener(this);
}
public void paint(Graphics g) {
super.paint(g);
Point p = this.getMousePosition();
if (p == null && click % 2 == 1) {
return;
}
if (click % 2 == 0 && (point1 == null || point2 == null)) {
return;
}
if (click % 2 == 0) {
if (isOval) {
int w = point2.x - point1.x;
int h = point2.y - point1.y;
int r = (int) Math.sqrt(w * w + h * h);
g.drawOval(point1.x - r / 2, point1.y - r / 2, r + r / 2, r
+ r / 2);
} else {
g.drawRect(point1.x, point1.y, point2.x - point1.x,
point2.y - point1.y);
}
return;
}
if (isOval) {
if (click % 2 == 1) {
int w = p.x - point1.x;
int h = p.y - point1.y;
int r = (int) Math.sqrt(w * w + h * h);
g.drawOval(point1.x - r / 2, point1.y - r / 2, r + r / 2, r
+ r / 2);
}
} else {
g.drawRect(point1.x, point1.y, p.x - point1.x, p.y - point1.y);
}
}
public void mouseClicked(MouseEvent mouseevent) {
click++;
if (click % 2 == 1) {
point1 = mouseevent.getPoint();
} else {
point2 = mouseevent.getPoint();
}
}
public void mouseEntered(MouseEvent mouseevent) {
}
public void mouseExited(MouseEvent mouseevent) {
}
public void mousePressed(MouseEvent mouseevent) {
}
public void mouseReleased(MouseEvent mouseevent) {
}
}
class MyTimesk extends TimerTask {
public void run() {
repaint();
}
}
}

Ⅹ java小程序源代碼

importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;

publicclassTest3
{
publicstaticvoidmain(String[]args)throwsIOException
{
FileOutputStreamoutput=newFileOutputStream(newFile("set.ini"));
output.write(123);
output.close();
FileInputStreaminput=newFileInputStream(newFile("set.ini"));
System.out.println(input.read());
input.close();
}
}

閱讀全文

與java小程序直播系統源碼相關的資料

熱點內容
多個jpg合成pdf 瀏覽:929
pdf轉word是圖片 瀏覽:939
程序員看不懂怎麼辦 瀏覽:271
linux操作系統題 瀏覽:765
單片機無符號數加法 瀏覽:227
應用隱藏加密怎麼關閉 瀏覽:269
汽車空調的壓縮機電線有什麼用 瀏覽:429
電腦加密圖片如何取消加密 瀏覽:340
慧凈電子51單片機視頻 瀏覽:343
javamap賦值 瀏覽:165
什麼app可以玩掌機游戲 瀏覽:46
java簡單聊天室 瀏覽:462
通用汽車編程軟體 瀏覽:432
一級抗震框架梁箍筋加密區規定是多少 瀏覽:974
教你如何把安卓手機變成蘋果 瀏覽:11
app編譯分類 瀏覽:323
怎麼用伺服器的資源包 瀏覽:199
oa軟體手機登陸伺服器地址 瀏覽:289
androidrtp打包 瀏覽:723
信息被加密碼了怎麼辦 瀏覽:420