java界面设计主界面_java界面设计,这个界面该怎么设计啊,求高手指点啊

展开全部

按照你的要求编写的Java程序如下:import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Arrays;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextArea;

import javax.swing.JTextField;

public class CCG extends JFrame implements ActionListener{

JLabel jl1=new JLabel("35选7",JLabel.LEFT);

JLabel jl2=new JLabel("输入选号:");

JLabel jl3=new JLabel("当前选号:");

JLabel jl4=new JLabel();

JTextField jtf=new JTextField(5);

JTextArea jta=new JTextArea(5,20);

JButton jb1=new JButton("添加本62616964757a686964616fe58685e5aeb931333361303639组号码");

JButton jb2=new JButton("验证并保存到文件");

JPanel jp1=new JPanel();

JPanel jp2=new JPanel();

JPanel jp3=new JPanel();

JPanel jp4=new JPanel();

JPanel jp5=new JPanel();

JPanel jp6=new JPanel();

JPanel jp7=new JPanel();

boolean saveFlag=false;

CCG(){

super("Lottery");

jtf.addActionListener(this);

jb1.addActionListener(this);

jb2.addActionListener(this);

jl1.setFont(new Font(null,Font.BOLD,20));

jp1.setLayout(new FlowLayout(FlowLayout.LEFT));

jp1.add(jl1);

jp1.setBorder(BorderFactory.createEtchedBorder ());

jp4.setLayout(new FlowLayout(FlowLayout.LEFT));

jp4.add(jl2);jp4.add(jtf);

jp5.setLayout(new FlowLayout(FlowLayout.LEFT));

jp5.add(jl3);jp5.add(jl4);

jp6.setLayout(new FlowLayout(FlowLayout.LEFT));

jp6.add(jb1);

jp2.setLayout(new GridLayout(3,1));

jp2.add(jp4);jp2.add(jp5);jp2.add(jp6);

jp2.setBorder(BorderFactory.createEtchedBorder ());

jp3.setLayout(new FlowLayout(FlowLayout.LEFT));

jp3.add(jta);jp3.add(jb2);

jp3.setBorder(BorderFactory.createEtchedBorder ());

jp7.setLayout(new GridLayout(2,1));

jp7.add(jp2);

jp7.add(jp3);

add(jp1,BorderLayout.NORTH);

add(jp7,BorderLayout.CENTER);

setSize(400, 300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setVisible(true);

}

@Override

public void actionPerformed(ActionEvent ae) {

if(ae.getSource()==jtf){

if(jtf.getText().trim().equals("")){

jl4.setText("");

}else{

int n=Integer.parseInt(jtf.getText().trim());

String str="";

if(n<10)str="0"+n;

else str=n+"";

if(jl4.getText().trim().contains(str)){

JOptionPane.showMessageDialog(null, "输入的数重复!");

jtf.requestFocus();

return;

}

int num=Integer.parseInt(str);

if(num<1 || num>35){

JOptionPane.showMessageDialog(null, "输入的数需要在1-35之间!");

jtf.requestFocus();

return;

}

if(jl4.getText().trim().equals("")){

int t=Integer.parseInt(jtf.getText().trim());

if(t<10) jl4.setText("0"+t);

else jl4.setText(""+t);

}else{

String[]a=(jl4.getText().trim()+","+jtf.getText().trim()).split(",");

if(a.length>7){

JOptionPane.showMessageDialog(null, "输入的数超过7个!");

jtf.requestFocus();

return;

}

int []b=new int[a.length];

for(int i=0;i

b[i]=Integer.parseInt(a[i].trim());

}

Arrays.sort(b);

String s="";

for(int i=0;i

if(i==b.length-1)

if(b[i]<10)s=s+"0"+b[i];

else s=s+b[i];

else

if(b[i]<10)s=s+"0"+b[i]+",";

else s=s+b[i]+",";

}

jl4.setText(s);

}

}

}

if(ae.getSource()==jb1){

jta.append(jl4.getText().trim()+"\n");

saveFlag=true;

}

if(ae.getSource()==jb2){

if(saveFlag==true){

BufferedWriter bw = null;

try {

bw=new BufferedWriter(new FileWriter("lottery.txt",true));

String s=random();

bw.append("本期开奖号码:"+s);

bw.newLine();

String[]a=jta.getText().split("\n");

for(int i=0;i

int count=0;

String[]b=a[i].split(",");

String tmp="";

for(int j=0;j

if(s.contains(b[j].trim()))count++;

if(j==b.length-1){

tmp=tmp+b[j].trim();

}else{

tmp=tmp+b[j].trim()+",";

}

}

String tmpwrite=tmp+" - "+count;

bw.append(tmpwrite);

bw.newLine();

}

bw.flush();

System.out.println("保存完毕!");

saveFlag=false;

} catch (IOException e) {

e.printStackTrace();

}finally{

try {

bw.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

}

public String random() {

int []a=new int[7];

int count=0;

while(count<7){

boolean flag=false;

int tmp=(int)(Math.random()*35)+1;

for(int i=0;i

if(tmp==a[i]){

flag=true;

}

}

if(flag==false){

a[count]=tmp;

count++;

}

}

Arrays.sort(a);

String s="";

for(int i=0;i

if(i==a.length-1){

if(a[i]<10){

s=s+"0"+a[i];

}else{

s=s+a[i];

}

}else{

if(a[i]<10){

s=s+"0"+a[i]+",";

}else{

s=s+a[i]+",";

}

}

}

return s;

}

public static void main(String[] args) {

new CCG();

}

}

运行结果:

877d57ae3d8ff898664b17a4ec9a41a4.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值