
正文
微息小java程序代码 java设计微信小程序
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java小程序编写
楼主,以下是我的实现方式,看看是不是你想要的,哪里不清楚的可以单独M我。
import java.util.Arrays;
import java.util.Comparator;
public class Student {
private int id;
private String name;
private String birthday;
public Student(int id, String name, String birthday) {
this.id = id;
this.name = name;
this.birthday = birthday;
}
public static void main(String[] args) {
Student s1 = new Student(1, "张三", "1983-01-22");
Student s2 = new Student(2, "张一", "1983-01-21");
Student s3 = new Student(3, "张笑一", "1983-01-27");
Student s4 = new Student(4, "张含一", "1983-01-01");
Student[] students = { s1, s2, s3, s4 }; //将4个学生对象装入数组中
//现根据出生日期对数组元素进行排序,由于String已经实现了Comparable接口,可以直接利用compareTo方法进行比较
Arrays.sort(students, new ComparatorStudent() {
public int compare(Student o1, Student o2) {
return o1.getBirthday().compareTo(o2.getBirthday());
}
});
//打印排序后的结构
System.out.println(Arrays.toString(students));
Student[] newStudents = new Student[students.length];
int i = 0;
for (Student s : students) {
if (s.getName().indexOf("一") != -1) {
newStudents[i] = s;
i++;
}
}
//打印搜索出的姓名含“一”的学生
System.out.println(Arrays.toString(newStudents));
}
@Override
public String toString() {
// TODO 自动生成方法存根
return "Student姓名:" + this.name + ",出生日期:" + this.birthday;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
相关问答
Q1: 微信小程序什么比较好写
1、自己会代码的:
可以使用微信开发者工具编写小程序代码。
参照微信开发者工具是在代码的基础上,如果你懂小程序的开发语言,例如java。那么你可以参照微信开放文档进行制作,网络上也有相关的小程序开发教程视频,遇到不懂得也可以在微信开放社区咨询相关人员。
2、不会代码的:
当然,你也可以使用第三方平台简单的拖动组件小程序开发工具。
第三方小程序开发工具:
通过拖动组件开发自己的小程序,这样就不需要有编程基础。通过小程序开发工具的背景就像构建积木游戏一样简单。个人可以很容易地制作自己的程序,而且功能也很强大,还有视频教学,帮助中心也有相关的文章教程。
微信小程序用什么软件开发?总的来说,如果你会代码的话,可以选择小程序开发工具,如果你不会代码的话,纯小白的话,选择第三方小程序开发平台会比较便捷。
Q2: 如何用JAVA语言编写计算器小程序?
具体代码如下:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Calculator extends JFrame implements ActionListener {
private JFrame jf;
private JButton[] allButtons;
private JButton clearButton;
private JTextField jtf;
public Calculator() {
//对图形组件实例化
jf=new JFrame("任静的计算器1.0:JAVA版");
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(){
System.exit(0);
}
});
allButtons=new JButton[16];
clearButton=new JButton("清除");
jtf=new JTextField(25);
jtf.setEditable(false);
String str="123+456-789*0.=/";
for(int i=0;iallButtons.length;i++){
allButtons[i]=new JButton(str.substring(i,i+1));
}
}
public void init(){
//完成布局
jf.setLayout(new BorderLayout());
JPanel northPanel=new JPanel();
JPanel centerPanel=new JPanel();
JPanel southPanel=new JPanel();
northPanel.setLayout(new FlowLayout());
centerPanel.setLayout(new GridLayout(4,4));
southPanel.setLayout(new FlowLayout());
northPanel.add(jtf);
for(int i=0;i16;i++){
centerPanel.add(allButtons[i]);
}
southPanel.add(clearButton);
jf.add(northPanel,BorderLayout.NORTH);
jf.add(centerPanel,BorderLayout.CENTER);
jf.add(southPanel,BorderLayout.SOUTH);
addEventHandler();
}
//添加事件监听
public void addEventHandler(){
jtf.addActionListener(this);
for(int i=0;iallButtons.length;i++){
allButtons[i].addActionListener(this);
}
clearButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Calculator.this.jtf.setText("");
}
});
}
//事件处理
public void actionPerformed(ActionEvent e) {
//在这里完成事件处理 使计算器可以运行
String action=e.getActionCommand();
if(action=="+"||action=="-"||action=="*"||action=="/"){
}
}
public void setFontAndColor(){
Font f=new Font("宋体",Font.BOLD,24);
jtf.setFont(f);
jtf.setBackground(new Color(0x8f,0xa0,0xfb));
for(int i=0;i16;i++){
allButtons[i].setFont(f);
allButtons[i].setForeground(Color.RED);
}
}
public void showMe(){
init();
setFontAndColor();
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Calculator().showMe();
}
}
关于微息小java程序代码和java设计微信小程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






