当前位置:
文档之家› java 知识点总结.ppt
java 知识点总结.ppt
Layout Flow Layout The default layout of JPanel Border Layout The default layout of JFrame Grid Layout
ScrollPane JScrollPane scrollPane = new JScrollPane(textArea);
factory methods LocalDate rightNow = LocalDate.now(); LocalDate newYearsEve = LocalDate.of(2017, 9, 25); System.out.println(rightDate.getYear()); System.out.println(rightDate.getMonthValue()); System.out.println(rightDate.getDayOfMonth());
int mode = 0; if (bold.isSelected()) mode += Font.BOLD; if (italic.isSelected()) mode += Font.ITALIC; label.setFont(new Font("Serif", mode, FONTSIZE)); };
Special objects Integer Double
Comparator Arrays.sort(stus, new Comparator<Student>() {
public int compare(Student s1, Student s2) { return s2.getName().compareTo(s1.getName());
label.setFont( new Font((String)faceCombo.getSelectedItem(),
Font.PLAIN, 24)));
menubar setJMenuBar();
toolbar JToolBar bar = new JToolBar(); // Define a button with a given icon JButton btnRed = new JButton(new ImageIcon("red-ball.gif")); // Specify the action btnRed.addActionListener(e -> label.setForeground(Color.red)); // Add the button to the bar bar.add(btnRed);
Literals hex 0xCAFE octal 031 Binary 0b1111_0100_0010_0100_0000 Double.POSTIVE_INFINITY正无穷大 Double.NEGATIVE_INFINITY 负无穷大
Use super to avoid recursive call public class Manager extends Employee {
label.setText(inputText);
Arrays.toString();
• Returns an integer indicating the option selected by the user
• Yes : 0 • No : 1 • Cancel : 2 • Close : -1
Input Dialog
String inputText = JOptionPane.showInputDialog("What's your favorite book?"); // Set the label content if (inputText != null)
ArrayList ArrayList<Employee> eList = new ArrayList<>(); eList.add(LiLei); // Print the second one System.out.println(eList.get(1)); // Set the second to Jerry eList.set(1, Jerry);
setbackgroundcolor bRed.addActionListener((e) -> {
getContentPane().setBackground(Color.red); bPanel.setBackground(Color.red); er checkbListener = event -> {
Special final 只生成一次 static :A static field is also called a class field, which means that the static field is shared across all its objects. 只保存最近赋值,所有对象通用,类似union static final:A static final field is a shared constant across all its objects
JVM Java Virtual Machine
JDK Java Development Kit
JRE Java Runtime Environment
IDE Integrated Development Environment集成开发环境
GUI Graphical User Interface
Application vs. Applet
} });
Lambda Arrays.sort(intArr, new Comparator<Integer>() {
public int compare(Integer i, Integer j) { return j - i;
} Arrays.sort(stus, (s1,s2) -> s2.getName().compareTo(s1.getName()));
Message Dialog
JOptionPane.showMessageDialog(null, "Hello the Dialog World!");
Confirm Dialog
int retConfirm = JOptionPane.showConfirmDialog(null, "Accept the offer?");
comment Multi-line comments:
/* like this ...
*/ Documentation comments: /** * This is the first sample program in Core Java Chapter 3 * @version 1.01 1997-03-22 * @author Gary Cornell */
StringBuilder builder = new StringBuilder(); builder.append(‘a’); builder.append(“cat”); String completedString = builder.toString();
Predefined class Date b_day = new Date(); System.out.println(b_day); // get the year System.out.println(b_day.getYear()); System.out.println(b_day.getMonth()); ......
private double bonus;
public double getSalary() { return super.getSalary() + bonus;
} }
Object: The Cosmic Superclass Any object or array reference can be stored in a variable of type Object: System.out.println(((Employee)obj1).getName()); Object obj2 = new int[10]; ((int[])obj2)[0] = 1; System.out.println(((int[])obj2)[0]);
CombpBox JComboBox<String> faceCombo = new JComboBox<>(); faceCombo.addItem("Serif"); faceCombo.addItem("SansSerif"); faceCombo.addItem("Monospaced"); faceCombo.addItem("Dialog"); faceCombo.addItem("DialogInput"); faceCombo.addActionListener(event ->
System.out.println(Arrays.toString(stus));
ScreenSize Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Resizable()
draw DrawLine DrawRect DrawOval
enum type enum Size { SMALL, MEDIUM, LARGE, EXTRA_LARGE };
Size s = Size.MEDIUM;
string String greeting = "Hello"; String s = greeting.substring(1, 3);