格式化
DecimalFormat pre = new DecimalFormat(“”);
JTextField output;
output.setText(pre.format(result));
Applet
题1
import java.applet.*
import java.awt.Graphics;
public class Java_1 extends Applet {
public void paint(Graphics g){
g.drawString("欢迎您",25,25);
}
}
题2
import java.awt.*;
import jave.applet.*;
public class Java_2 extends Applet
{
TextArea outputArea;
public void init(){
setLayout(new BorderLayout());
outputArea = new TextArea();
add(outputArea);
for(long i = 0; i <= 10; i++){
outputArea.append(i+"!=" +hello(i) +"\n");
}
}
}
题3
// 碰到有html的程序,一定是继承JApplet
import java.awt.*;
import javax.swing.*;
public class Java_3 extends JApplet
{
// JApplet的第一个方法是 init
public void init(){
}
}
JOptionPane
题1
import javax.swing.JOptionPane;
// 需要记住的代码
JOptionPane.showMessageDialog(null, output, "",...)
其他的有: showConfirmDialog(), showInputDialog(), showOptionDialog()
JOptionPane.showMessageDialog(null, output, "字符串",
JOptionPane.INFORMATION_MESSAGE);
题2
// 输入框
String input = JOptionPane.showInputDialog("输入一个整数");
Container c = getContentPane()
JFrame相关
题1
import javax.swing.*;
public SimpleThread(String str) {
super(str);
}
题2
import javax.swing.*;
class BeijingPanel extends JPanel
{
public BeijingPanel(){
setLayout(new BorderLayout());
}
}
frame.getContentPane().add();
题3
import java.swing.JFrame;
str.length();
str.charAt(3);
// 使窗口隐藏
frame.dispose(); //使窗口隐藏或消除
题4
JMenu m1 = new JMenu("Edit");
SelectedFile().getPath()
JButton calcBtn = new JButton("计算");
题5
public class Java_3 implements ActionListener
{
JFileChooser fc = new JFileChooser();
int selected = fc.showOpenDialog();
File myFile = fc.showOpenDialog();
myFile.getName()
}
题6
JFrame f = new JFrame();
Container contentPane = f.getContentPane();
JTable table = new JTable();
table.addMouseListener(new MouseApapter());
计算机专业java题7
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
题8
JTextArea result = new JTextArea();
result.append(str)
Listener
题1
public class Java_3 extends MouseAdapter implements ActionListener{}
class MouseMotion extends MouseMotionAdapter{}
题2
class A implements ActionListener
{
public void actionPerformed(ActionEvent event)
}
题3
int n = und(21*x)
input.addActionListener(this);
输入输出流
题1
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File()))
oos.writeObject(new User())
ObjectInputStream ooi = new ObjectInputStream(new FileInputStream(new File()))
ooi.readObject()
import java.io.Serializable
题2
FileWriter out = new FileWriter(new File(""));
FileReader in = new FileReader(new File(""));
class ImagePanel extends JPanel
题3
DataOutputStream out = new DataOutputStream(new FileOutputStream(""));
out.writeChar(aa[i]);
题4
import java.awt.*;
FileWriter out = new FileWriter("");
out.write(str);
解题思想
题1
2008 -> 8002
int a,x = 2008;
while(x!=0){
a = x % 10;
x = x / 10;
}
题2
矩阵乘法
public class Java_2 {
public static void main(String args[]) {
int [][]a = {{2, 3, 4}, {4, 6, 5}};
int [][]b = {{1, 5, 2, 8}, {5, 9, 10, -3}, {2, 7, -5, -18}};
//*********Found**********
int [][]c = new int[2][4];
for (int i = 0; i < 2; i++) {
//*********Found**********
for (int j = 0; j <4; j++) {
//*********Found**********
c[i][j] = 0;
for (int k = 0; k < 3; k++)
//*********Found**********
c[i][j] += a[i][k] * b[k][j];
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}
题3
import java.io.*;
public class Java_1
{
public static void main(String[] args) throws Exception{
InputStreamReader ir = new InputSteamReader(System.in);
BufferedReader in = new BufferedReader(ir);
String s = in.readLine();
int year = Integer.parseInt(s);
if(year%4==0 && year%100!=0 || year%400==0){
System.out.println(year+"是闰年");
}else{
System.out.println(year+"不是闰年")
}
}
}
题4
自定义排序
public class Java_2
{
public static void main(String[] args)
{
Student[] java = new Student[3];
java[0] = new Student("李明", 80);
java[1] = new Student("赵冬", 75);
java[2] = new Student("王晓", 98);
//*********Found**********
Arrays.sort(java);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论