java小程序源代码,简单点的,100多行,谁有啊

java小程序源代码,简单点的,100多行,谁有啊,第1张

// My car shopjava

import javaawt;

import javaawtevent;

import javaxswing;

import javaxswingborder;

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

contentPanesetLayout( null );

// set up windowJPanel

windowJPanel = new JPanel();

windowJPanelsetBounds( 10, 20, 340, 200 );

windowJPanelsetBorder( new LineBorder( ColorBLACK ) );

windowJPanelsetLayout( null );

contentPaneadd( windowJPanel );

// set up oneIconJLabel

oneIconJLabel = new JLabel();

oneIconJLabelsetBounds( 10, 20, 100, 65 );

oneIconJLabelsetIcon( new ImageIcon( "images/阿斯顿马丁jpg" ) );

windowJPaneladd( oneIconJLabel );

// set up oneJLabel

oneJLabel = new JLabel();

oneJLabelsetBounds( 10, 60, 100, 70 );

oneJLabelsetText( "阿斯顿马丁" );

oneJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( oneJLabel );

// set up twoIconJLabel

twoIconJLabel = new JLabel();

twoIconJLabelsetBounds( 120, 20, 100, 65 );

twoIconJLabelsetIcon( new ImageIcon( "images/美洲虎jpg" ) );

windowJPaneladd( twoIconJLabel );

// set up twoJLabel

twoJLabel = new JLabel();

twoJLabelsetBounds( 110, 60, 100, 70 );

twoJLabelsetText( "美洲虎" );

twoJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( twoJLabel );

// set up threeIconJLabel

threeIconJLabel = new JLabel();

threeIconJLabelsetBounds( 230, 20, 100, 65 );

threeIconJLabelsetIcon( new ImageIcon(

"images/凯迪拉克jpg" ) );

windowJPaneladd( threeIconJLabel );

// set up threeJLabel

threeJLabel = new JLabel();

threeJLabelsetBounds( 230, 60, 100, 70);

threeJLabelsetText( "凯迪拉克" );

threeJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( threeJLabel );

// set up fourIconJLabel

fourIconJLabel = new JLabel();

fourIconJLabelsetBounds( 10, 100, 100, 65 );

fourIconJLabelsetIcon( new ImageIcon( "images/罗孚jpg" ) );

windowJPaneladd( fourIconJLabel );

// set up fourJLabel

fourJLabel = new JLabel();

fourJLabelsetBounds( 10, 150, 50, 70 );

fourJLabelsetText( "罗孚" );

fourJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( fourJLabel );

// set up fiveIconJLabel

fiveIconJLabel = new JLabel();

fiveIconJLabelsetBounds( 120, 100, 100, 65 );

fiveIconJLabelsetIcon( new ImageIcon(

"images/劳斯莱斯jpg" ) );

windowJPaneladd( fiveIconJLabel );

// set up fiveJLabel

fiveJLabel = new JLabel();

fiveJLabelsetBounds( 110, 150, 100, 70 );

fiveJLabelsetText( "劳斯莱斯" );

fiveJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( fiveJLabel );

// set up sixIconJLabel

sixIconJLabel = new JLabel();

sixIconJLabelsetBounds( 230, 100, 100, 65 );

sixIconJLabelsetIcon( new ImageIcon( "images/别克jpg" ) );

windowJPaneladd( sixIconJLabel );

// set up sixJLabel

sixJLabel = new JLabel();

sixJLabelsetBounds( 230, 150, 100, 70 );

sixJLabelsetText( "别克" );

sixJLabelsetHorizontalAlignment( JLabelCENTER );

windowJPaneladd( sixJLabel );

// set up enterJButton

enterJButton = new JButton();

enterJButtonsetBounds( 390, 160, 135, 30 );

enterJButtonsetText( "Enter" );

contentPaneadd( enterJButton );

enterJButtonaddActionListener(

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();

clearJButtonsetBounds( 390, 200, 135, 30 );

clearJButtonsetText( "Clear" );

contentPaneadd( clearJButton );

// set up inputJLabel

inputJLabel = new JLabel();

inputJLabelsetBounds( 390, 25, 135, 25 );

inputJLabelsetText( "Please make selection:" );

contentPaneadd( inputJLabel );

selectCountryJComboBox = new JComboBox( cars );

selectCountryJComboBoxsetBounds( 390, 50, 135, 21 );

selectCountryJComboBoxsetMaximumRowCount( 3 );

contentPaneadd( selectCountryJComboBox );

// set up inputJTextField

inputJLabel2 = new JLabel();

inputJLabel2setBounds( 390, 80, 150, 20 );

inputJLabel2setText( "Input the Numble:" );

contentPaneadd( inputJLabel2 );

// set up inputJTextField

inputJTextField2 = new JTextField();

inputJTextField2setBounds( 390, 100, 135, 25 );

inputJTextField2setHorizontalAlignment( JTextFieldRIGHT );

contentPaneadd( inputJTextField2 );

clearJButtonaddActionListener(

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();

displayJTextAreasetBounds( 10, 237,515, 70 );

displayJTextAreasetEditable( false );

contentPaneadd( 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

inputJTextField2setText( "" );

displayJTextAreasetText("");

} // end method clearJButtonActionPerformed

private void enterJButtonActionPerformed( ActionEvent event )

{

double z;

double c;

int x;

int y;

x=selectCountryJComboBoxgetSelectedIndex();

y=IntegerparseInt(inputJTextField2getText());

double discountRate;

int amount = IntegerparseInt( inputJTextField2getText());

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]yc;

displayJTextAreaappend("你选择的是:"+cars[x]+";"+

"它的单价是:"+jiage[x]+";" +"你购买该产品的数量是:"+y+"," +"\n"+"该数量的折扣是:"

+discountRate + " %"+";"+"本次消费的总价格是:"+z+"元"+"!"+"\n");

}

public static void main( String args[] )

{

carshop application = new carshop();

applicationsetDefaultCloseOperation( JFrameEXIT_ON_CLOSE );

} // end method main

} // end class carshop

public class Test {

public static void main(String[] args) {

int count = 0;

for (int i = 100; i <= 1000; i++) {

if (i % 2 == 0) {

Systemoutprint(i + " ");

if (++count % 10 == 0) {

Systemoutprint("\n");

}

}

}

}

}

随便写个小游戏小工具呗,比如 写个猜数字游戏,系统自动生成一个100内的数字,你每次猜一个数字输入,系统返回大了还是小了或者中了再或者写一个查询身体质量指数BMi指数工具用户输入身高和体重,返回健康状态及友好提示语,等等主要看面对问题的时候,你的想法思路设计思想,面向过程还是面向对象或者面向别的什么

在用Java进行开发前,一定要牢牢遵守Java的开发规范,只有这样你的Java开发之路才能更加顺畅。而掌握相应的Java开发技巧,则可以让你工作起来事半功倍。那在编写代码时有什么开发规范和技巧呢?电脑培训给你详细介绍一下吧。

1、代码编写规范:

代码编写遵守Java通用开发规范和必联代码开发规范;

每个类及方法都要有合理的注释,并且对注释要持续维护;

根据接口需求编写单元测试用例,再编写实现类使得单元测试通过,如此循环往复以使得所有的单元测试通过;

要求每个Java方法的代码行数不能超过100行;

代码编写按照功能划分,一个接口分为多个方法,每一个方法做什么事情,做到思路清晰;

接口设计尽量做到多兼容性,方便后期开发。

2、数据库设计及SQL规范

不使用MySQL数据库外键约束,通过应用程序逻辑实现关联约束;

适当建立索引,经常作为查询条件的字段、唯一性程度高、长度不是很长的、数量不宜太多,一般一个表的索引数目在5个以内;

表名长度不能超过30个字符,表名最好选择一个单词,能够准确清晰明了地表示实体含义,若必须多个单词则以下划线“_”分隔,单词所有字母均小写;

思路分析:

需要判断100到1000所有的整数,所以需要使用循环结构进行遍历。

因为循环的初始值和终止值是固定的,所以使用for循环为最佳。

题目要求每行显示10个数字,所以需要对打印的数字进行计数,每打印10个进行换行。

示例代码:

public static void main(String[] args) {

    int count = 0;    //结果计数

    for (int i = 100; i <= 1000; i++) {

        if ((i % 5 == 0) || (i % 6 == 0)) {

            count++;

            Systemoutprint(i + ",");

            if (count % 10 == 0) {    //每打印10个数字,进行一次换行

                Systemoutprintln();

            }

        }

    }

}

//有窗口的 1+2+3++到某一个数

import javaawtColor;

import javaawtFont;

import javaawtContainer;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingWindowConstants;

public class AbsolutePosition extends JFrame

{

Font F =new Font("宋体",1,20);

int A=1;

int B=0;

int C=0;

int Undo=0;

public void ChangeNum(int X)

{

A=A+X;

C=0;

B=0;

while(C<Mathabs(A))

{

C=C+1;

B=B+C;

}

if(A<0)

{

B=-B;

}

}

public AbsolutePosition()

{

setTitle("算+一个整数");

setLayout(null);

setResizable(false);

Container container = getContentPane();

JButton B1=new JButton("+1");

JLabel L1=new JLabel("请计算");

JButton B2=new JButton("-1");

JButton B3=new JButton("+10");

JButton B4=new JButton("-10");

JButton B5=new JButton("+100");

JButton B6=new JButton("-100");

JButton B7=new JButton("设数为0");

JButton B8=new JButton("撤销");

L1setBounds(120, 100, 300, 70);

B1setBounds(120, 200, 200, 40);

B2setBounds(320, 200, 200, 40);

B3setBounds(120, 240, 200, 40);

B4setBounds(320, 240, 200, 40);

B5setBounds(120, 280, 200, 40);

B6setBounds(320, 280, 200, 40);

B7setBounds(120, 160, 200, 40);

B8setBounds(320, 160, 200, 40);

B1addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(1);

L1setText(""+B+"(+"+A+")");

}

});

B2addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(-1);

L1setText(""+B+"(+"+A+")");

}

});

B3addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(+10);

L1setText(""+B+"(+"+A+")");

}

});

B4addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(-10);

L1setText(""+B+"(+"+A+")");

}

});

B5addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(+100);

L1setText(""+B+"(+"+A+")");

}

});

B6addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

ChangeNum(-100);

L1setText(""+B+"(+"+A+")");

}

});

B7addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

Undo=A;

A=0;

ChangeNum(0);

L1setText(""+B+"(+"+A+")");

}

});

B8addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent E)

{

A=Undo;

ChangeNum(0);

L1setText(""+B+"(+"+A+")");

}

});

L1setFont(F);

L1setForeground(ColorBLUE);

L1setBackground(ColorWHITE);

containeradd(B1);

containeradd(L1);

containeradd(B2);

containeradd(B3);

containeradd(B4);

containeradd(B5);

containeradd(B6);

containeradd(B7);

containeradd(B8);

setVisible(true);

setSize(660,480);

setDefaultCloseOperation(WindowConstantsEXIT_ON_CLOSE);

}

public static void main(String [] args)

{

new AbsolutePosition();

}

}

以上就是关于java小程序源代码,简单点的,100多行,谁有啊全部的内容,包括:java小程序源代码,简单点的,100多行,谁有啊、JAVA编写程序,输出100到1000间的所有偶数,并要求每行输出“10个数字、Java老师要求设计一个Java小程序,100~200行,解决一个有意思的问题,用到面向对象的概念,等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9875888.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存