java界面转换源代码 java源代码怎么变成软件
求一个,java图形化界面的源码
自己写的石头剪子布代码,有图形界面,可以把自己选中的图片命名为.jpg放到工程目录下做背景图片。//////////////////////////// package HomeWork;
创新互联公司服务项目包括惠城网站建设、惠城网站制作、惠城网页制作以及惠城网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,惠城网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到惠城省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class StoneShearsSack { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new StoneWindow("Sample Game");
}
}
final class StoneWindow extends JFrame implements ActionListener,ItemListener{
JLabel win,draw,lose,score,count;
JTextArea text;
JComboBox list;
JButton fight,clear;
int swin,sdraw,slose,sscore;
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
String str1,str2,str3;
Random rdm = new Random();
int flag,random ,flag1, count1;
//final ImageIcon con = new ImageIcon("a.jpg") ;
public StoneWindow(String s){
setTitle("Sample Game");
fight = new JButton("出招");
clear = new JButton("清除分数");
//final ImageIcon con = new ImageIcon("b.jpg") ;
text = new JTextArea(){
final ImageIcon con = new ImageIcon("a.jpg");
Image mg = con.getImage();
{setOpaque(false);}
public void paintComponent(Graphics g){
g.drawImage(mg, 0, 0, this);
super.paintComponent(g);
}
};
text.setForeground(Color.black);
Font f = new Font("华文行楷",Font.BOLD,50);
text.setFont(f);
list = new JComboBox();
list.addItem("石头");
list.addItem("剪子");
list.addItem("布");
panel2.setBackground(Color.blue);
panel2.add(list);
panel2.add(fight);
panel2.add(clear);
panel2.setPreferredSize(new Dimension(900,50));
list.addItemListener(this);
fight.addActionListener(this);
clear.addActionListener(this);
win = new JLabel("赢:" + swin);
draw = new JLabel(" 和:" + sdraw);
lose = new JLabel(" 输:" + slose);
score = new JLabel(" 得分:" + sscore);
count = new JLabel(" 总局:" + count1);
Font f1 = new Font("宋体",1,30);
win.setFont(f1);
draw.setFont(f1);
lose.setFont(f1);
score.setFont(f1);
count.setFont(f1);
win.setForeground(Color.cyan);
draw.setForeground(Color.green);
lose.setForeground(Color.blue);
score.setForeground(Color.black);
count.setForeground(Color.pink);
panel1.setBackground(Color.red);
panel1.add(win);
panel1.add(draw);
panel1.add(lose);
panel1.add(score);
panel1.add(count);
panel1.setPreferredSize(new Dimension(900,50));
add(panel1,BorderLayout.NORTH);
add(text,BorderLayout.CENTER);
add(panel2,BorderLayout.SOUTH);
setBounds(100,100,900,450);
validate();
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == fight){
if(list.getSelectedItem() == "石头"){
flag = 0;
}
else if(list.getSelectedItem() == "剪子"){
flag = 1;
}
else if(list.getSelectedItem() == "布"){
flag = 2;
}
str1 = (String)list.getSelectedItem();
text.setText("");
text.append("\n");
text.append(" 你 出: " + str1 + "\n");
text.append(" 电脑出: " + this.random() + "\n");
text.append(" 结 果: " + this.result() + "\n");
this.finalresult();
}
if(e.getSource() == clear){
swin = 0;
sdraw = 0;
slose = 0;
sscore = 0;
count1 = 0;
text.setText("");
win.setText(" 赢:" + swin);
draw.setText(" 和:" + sdraw);
lose.setText(" 输:" + slose);
score.setText(" 得分:" + sscore);
count.setText(" 总局:" + count1);
}
}
public String random(){
random = rdm.nextInt(3);
if(random == 0)
str2 = "石头";
else if(random == 1)
str2 = "剪子";
else if(random == 2)
str2 = "布";
return str2;
}
public String result(){
if(random == flag){
str3 ="打平";
flag1 = 0;
}
else if(random flag flag == 1){
str3 = "你输了";
flag1 = 1;
}
else if(random flag random ==1){
str3 = "你输了";
flag1 = 1;
}
else if(random ==2 flag == 0){
str3 = "你输了";
flag1 = 1;
}
else{
str3 = "你赢了";
flag1 = 2;
}
return str3;
}
public void finalresult(){
if(flag1 == 0){
sdraw ++;
draw.setText(" 平:" + sdraw);
score.setText(" 得分:" + sscore);
}
if(flag1 == 1){
slose ++;
sscore = sscore - 10;
lose.setText(" 输:" + slose);
score.setText(" 得分:" + sscore);
}
if(flag1 == 2) {
swin ++;
sscore = sscore + 10;
win.setText(" 赢:" + swin);
score.setText(" 得分:" + sscore);
}
count1 = swin + slose + sdraw;
count.setText(" 总局:" + count1);
}
public void itemStateChanged(ItemEvent e){
}
}
求一java程序,一个界面计算器源代码,跪求大神,有注释最好。。
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class GUI extends JFrame implements ActionListener {//实现监听接口
JTextField field = new JTextField(15);
double num1=0,num2;
char op;
public GUI(){
setLayout(new BorderLayout(10,10));
JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p1.add(new JLabel("计算框:"));
p1.add(field);
add(p1,BorderLayout.NORTH);
JPanel p2 = new JPanel(new GridLayout(4,1));
//添加按钮
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
JButton bt3 = new JButton("3");
JButton bt4 = new JButton("4");
JButton bt5 = new JButton("5");
JButton bt6 = new JButton("6");
JButton bt7 = new JButton("7");
JButton bt8 = new JButton("8");
JButton bt9 = new JButton("9");
JButton bt0 = new JButton("0");
JButton btDel = new JButton("Del");
JButton btEqual = new JButton("=");
p2.add(bt1);p2.add(bt2);
p2.add(bt3); p2.add(bt4);
p2.add(bt5); p2.add(bt6);
p2.add(bt7);p2.add(bt8);
p2.add(bt9);p2.add(bt0);
p2.add(btDel);p2.add(btEqual);
add(p2,BorderLayout.CENTER);
JPanel p3 = new JPanel(new GridLayout(0,1));
JButton bta = new JButton("+");
JButton btb = new JButton("-");
JButton btc = new JButton("*");
JButton btd = new JButton("/");
p3.add(bta);p3.add(btb);
p3.add(btc);p3.add(btd);
add(p3,BorderLayout.EAST);
//添加监听器
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
bt4.addActionListener(this);
bt5.addActionListener(this);
bt6.addActionListener(this);
bt7.addActionListener(this);
bt8.addActionListener(this);
bt9.addActionListener(this);
bt0.addActionListener(this);
bta.addActionListener(this);
btb.addActionListener(this);
btc.addActionListener(this);
btd.addActionListener(this);
btDel.addActionListener(this);
btEqual.addActionListener(this);
}
//事件的响应
public void actionPerformed(ActionEvent e){
String str =e.getActionCommand();
String s1 = field.getText();
if(str!="+"str!="-"str!="*"str!="/"str!="="str!="Del"){//为数字按钮时
field.setText(s1+str);
}
else if(str=="Del"){//删除键
field.setText("");
str=null;
}
else if(str=="="){//等号按钮
s1 =field.getText();
String t2 ="";
int flag=0;//标记操作符的位置
if(s1.indexOf("+")!=-1)
flag = s1.indexOf("+");
if(s1.indexOf("-")!=-1)
flag = s1.indexOf("-");
if(s1.indexOf("*")!=-1)
flag = s1.indexOf("*");
if(s1.indexOf("/")!=-1)
flag = s1.indexOf("/");
for(int i=flag+1;is1.length();i++)
{
t2+=s1.charAt(i);//获得第二个操作数
}
num2 =Double.parseDouble(t2);//将第二个操作数转换为double
switch(op){
case '+': num1+=num2;break;
case '-': num1-=num2;break;
case '*': num1*=num2;break;
case '/': num1/=num2;break;
}
field.setText(s1+"="+num1+"");//显示在文本框里
}
else{//加减乘除符号
num1 = Double.parseDouble(field.getText());
field.setText(s1+str);
op = str.charAt(0);//获得操作符
}
}
public static void main(String[] args){
GUI frame = new GUI();
frame.setTitle("简易计算器");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
//frame.pack();
frame.setVisible(true);
}
}
不懂再问
如何用java做出左侧是菜单栏,单击,右侧可进行页面切换的效果,求源代码
1、网页:
(1)、用frameset加iframe
(2)、直接写好div+css,左侧导入菜单的页面(import/link),右侧导入不同的页面
2、PC端:
用东南西北中的那个布局 BorderLayout
文章标题:java界面转换源代码 java源代码怎么变成软件
文章出自:http://ybzwz.com/article/ddsepcg.html