.


:




:

































 

 

 

 





.

, .. .1 Object, .1 .., .2 ..

  • .
  • .
  • .
  • .

.

class A {... A() {...}...} class B extends A {... B() {... }...}

-

B b = new B();

A(), B().

A . , , , , , , , - .

Java . super, .

class X { X(int a) {... }...} class Y extends X { Y() { super(0);... }...}

super . , .

class Base { int x = 1; long y; Base(long y) { this.y = y; } Base() { this(0); // Base(long y) } public long f() { return x*y; }} class Derived extends Base { String name = ""; Derived(String name, long par) { super(par); // Base(long y) this.name = name; } public long g(int r) { return r+super.f(); // f() Base } public long f() { x++; return 2*y; }}

, Derived. Base x y f(). name g(...) f(), f() Base.

, g(...), f() Derived, f() Base. super. f() Derived.

Derived. , .

Derived d = new Derived("test", 10);long c = d.g(5);long p = d.f();

Java

C++ Java . .. . - ( ). .

Java. . "Tree". Java.

Dialog1. , .

// Dialog2.java// 2- Java. import java.awt.*;import java.awt.event.*;import javax.swing.*; public class Dialog2 extends JFrame { Dialog2() { super(" "); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { } setSize(300, 200); Container c = getContentPane(); c.add(new JLabel("Hello, ")); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); } public static void main(String[] args) { new Dialog2(); }}

Java, Dialog1.

.

// Dialog3.java// . import java.awt.*;import java.awt.event.*;import javax.swing.*; public class Dialog3 extends JFrame { JTextArea txt; Dialog3() { super(" "); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { } setSize(400, 200); Container c = getContentPane(); c.add(new JLabel("Hello, "), BorderLayout.NORTH); // 0 txt = new JTextArea(5, 30); // 1 JScrollPane pane = new JScrollPane(txt); // 2 c.add(pane, BorderLayout.CENTER); // 3 WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); } public void test() { txt.append(" \n"); txt.append(" \n"); } public static void main(String[] args) { Dialog3 d = new Dialog3(); d.test(); }}

Java. , VB, Java . . Layout' ("", ). BorderLayout ( Layout' JFrame). . , BorderLayout .

BorderLayout () .

1.

. ( add(...)) (. 0 3).

JTextArea / . , , JScrollPane, txt JTextArea.





:


: 2016-12-06; !; : 482 |


:

:

, , .
==> ...

1731 - | 1437 -


© 2015-2024 lektsii.org - -

: 0.013 .