Java
A1.java
class A1 { public static void main( String[] params ) { System.out.println("Sveikas, pasauli!"); } }
A2.java
public class A2 { public static void main( String[] params ) { System.out.println("Laba diena, " + params[0]); } }
A3.java
public class A3 { public static void main( String[] params ) { if ( params.length > 0 ) System.out.println("Laba diena, " + params[0]); } }
A4.java
public class A4 { public static void main( String[] params ) { for(int i = 0; i < params.length; i++) System.out.println(params[i]); } }
B1.java
// Java dokumentacija // http://java.sun.com/j2se/1.5.0/docs/api/ // http://www.allimant.org/javadoc/ //Viliaus Stakeno // http://www.mif.vu.lt/katedros/matinf/asm/vs/pask/java_pr/jv_pr.htm // http://www.mif.vu.lt/katedros/matinf/asm/vs/pask/java_pr/9_tema.htm import java.io.*; public class B1 { public static void main( String[] params ) { try { BufferedReader in = new BufferedReader( new FileReader("B1.java") ); String s = in.readLine(); System.out.println( s ); in.close(); } catch(IOException e) { System.out.println(e); } } }
B1A.java
import java.io.*; public class B1A { public static void main( String[] params ) throws IOException { BufferedReader in = new BufferedReader( new FileReader("B1.java") ); String s = in.readLine(); System.out.println( s ); in.close(); } }
B2.java
import java.io.*; public class B2 { public static void main( String[] params ) { try { BufferedReader in = new BufferedReader( new FileReader("B2.java") ); String s = in.readLine(); while (s != null) { System.out.println( s ); s = in.readLine(); } in.close(); } catch(IOException e) { System.out.println(e); } } }
B3.java
import java.io.*; public class B3 { public static void main( String[] params ) { try { BufferedReader in = new BufferedReader( new FileReader("B3.java") ); String s; while ( (s = in.readLine()) != null) { System.out.println( s ); } in.close(); } catch(IOException e) { System.out.println(e); } } }
BX.java
import java.io.*; public class BX { public static void main( String[] params ) { try { PrintWriter out = new PrintWriter ( new BufferedWriter( new FileWriter("rez.txt"))); out.println("Testas"); out.close(); } catch(IOException e) { System.out.println(e); } } }
C1.java
import java.io.*; import java.util.*; public class C1 { public static void main( String[] params ) { try { BufferedReader in = new BufferedReader( new FileReader("C1.java") ); String s = in.readLine(); StringTokenizer st = new StringTokenizer(s); while ( st.hasMoreTokens() ) { System.out.println( st.nextToken() ); } in.close(); } catch(IOException e) { System.out.println(e); } } }
C2.java
import java.io.*; import java.util.*; public class C2 { public static void main( String[] params ) { try { BufferedReader in = new BufferedReader( new FileReader("C2.java") ); String s = in.readLine(); while ( s != null ) { StringTokenizer st = new StringTokenizer(s); while ( st.hasMoreTokens() ) { System.out.println( st.nextToken() ); } s = in.readLine(); } in.close(); } catch(IOException e) { System.out.println(e); } } }
CX.java
import java.io.*; public class CX { public static void main( String[] a ) throws IOException { System.out.print("Enter number:"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input = in.readLine(); int i = Integer.parseInt(input); System.out.println( fact(i) ); } static int fact(int n) { int mult=1; for(int i=2; i<=n; i++) mult*=i; //mult=mult*i; return mult; } }
D.txt
3 1 Jonas 12 2 Ona 43 3 Petriukas 2
D1.java
import java.io.*; import java.util.*; class Irasas { int id; String vardas; int amzius; } class D1 { public static void main( String[] params ) { Irasas[] masyvas = null; try { BufferedReader in = new BufferedReader( new FileReader("D.txt") ); String s = in.readLine(); int eiluciu = Integer.parseInt(s); masyvas = new Irasas[eiluciu]; for(int i=0; i
D2.java
import java.io.*; import java.util.*; class Irasas { int id; String vardas; int amzius; public String toString() { return "" + id + " " + vardas + " " + amzius; } } class D2 { public static void main( String[] params ) { Irasas[] masyvas = null; try { BufferedReader in = new BufferedReader( new FileReader("D.txt") ); String s = in.readLine(); int eiluciu = Integer.parseInt(s); masyvas = new Irasas[eiluciu]; for(int i=0; i
D3.java
import java.io.*; import java.util.*; class Irasas { int id; String vardas; int amzius; Irasas(String s) { StringTokenizer st = new StringTokenizer(s); id = Integer.parseInt(st.nextToken()); vardas = st.nextToken(); amzius = Integer.parseInt(st.nextToken()); } public String toString() { return "" + id + " " + vardas + " " + amzius; } } class D3 { public static void main( String[] params ) { Irasas[] masyvas = null; try { BufferedReader in = new BufferedReader( new FileReader("D.txt") ); String s = in.readLine(); int eiluciu = Integer.parseInt(s); masyvas = new Irasas[eiluciu]; for(int i=0; i
D4.java
import java.io.*; import java.util.*; class Irasas { int id; String vardas; int amzius; Irasas(int id, String vardas, int amzius) { setValues(id, vardas, amzius); } Irasas(String s) { StringTokenizer st = new StringTokenizer(s); setValues(Integer.parseInt(st.nextToken()), st.nextToken(), Integer.parseInt(st.nextToken())); } public void setValues(int id, String vardas, int amzius) { this.id = id; this.vardas = vardas; this.amzius = amzius; } public String toString() { return "" + id + " " + vardas + " " + amzius; } } class D4 { public static void main( String[] params ) { Irasas[] masyvas = null; try { BufferedReader in = new BufferedReader( new FileReader("D.txt") ); String s = in.readLine(); int eiluciu = Integer.parseInt(s); masyvas = new Irasas[eiluciu]; for(int i=0; i
D5.java
import java.io.*; import java.util.*; class Irasas { int id; String vardas; int amzius; Irasas(int id, String vardas, int amzius) { setValues(id, vardas, amzius); } Irasas(String s) { StringTokenizer st = new StringTokenizer(s); setValues(Integer.parseInt(st.nextToken()), st.nextToken(), Integer.parseInt(st.nextToken())); } public void setValues(int id, String vardas, int amzius) { this.id = id; this.vardas = vardas; this.amzius = amzius; } public String toString() { return "" + id + " " + vardas + " " + amzius; } public int compareTo(Irasas kitas) { return this.vardas.compareTo(kitas.vardas); } } class D5 { public static void main( String[] params ) { Irasas[] masyvas = null; try { BufferedReader in = new BufferedReader( new FileReader("D.txt") ); String s = in.readLine(); int eiluciu = Integer.parseInt(s); masyvas = new Irasas[eiluciu]; for(int i=0; i
0 ) { System.out.println("didesnis"); } else { System.out.println("mazesnis ar lygus"); } } }
E1.java
class E1 { public static void main(String arg[]) { int atsitiktinis = 1 + (int)(5*Math.random()); System.out.println("Sveikas teigiamas atsitiktinis nuo 1 iki 5: "+atsitiktinis); } }
E2.java
import java.io.*; class E2 { public static String getLine() { String s = null; try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); s = in.readLine(); in.close(); }catch(IOException e) {} return s; } public static void main(String arg[]) { System.out.println("Rinkis: 1 ar 2? "); int sk = Integer.parseInt( getLine() ); switch(sk) { case 1 : System.out.println("Negodus :)"); break; case 5 : System.out.println("Godus :)"); break; default : System.out.println("Skaityt nemoki..."); } } }
G1.java
import javax.swing.*; class G1 { public static void main(String[] args) { JFrame frame = new JFrame("G1"); frame.setVisible(true); } }
G2.java
import javax.swing.*; class G2 { public static void main(String[] args) { JFrame frame = new JFrame("G2"); JLabel label = new JLabel("Hello"); frame.add(label); frame.pack(); frame.setVisible(true); } }
G3.java
import javax.swing.*; import java.awt.*; class G3 { public static void main(String[] args) { JFrame frame = new JFrame("G"); JLabel label = new JLabel("Hello"); frame.add(label); frame.setPreferredSize (new Dimension (800,500)); frame.setMinimumSize (new Dimension (800,500)); frame.pack(); frame.setVisible(true); } }
G4.java
import javax.swing.*; import java.awt.*; class G4 { public static void main(String[] args) { JFrame frame = new JFrame("G"); JLabel label = new JLabel("Hello"); frame.add(label); JButton button = new JButton("Hello"); frame.add(button); //Problemos..... frame.setPreferredSize (new Dimension (800,500)); frame.setMinimumSize (new Dimension (800,500)); frame.pack(); frame.setVisible(true); } }
G5.java
import javax.swing.*; import java.awt.*; class G5 { public static void main(String[] args) { JFrame frame = new JFrame("G"); frame.setLayout(new FlowLayout()); JLabel label = new JLabel("Hello"); frame.add(label); JButton button = new JButton("Hello"); frame.add(button); //Problemos..... frame.setSize (new Dimension (800,500)); frame.setVisible(true); } }
G6.java
import javax.swing.*; import java.awt.*; class G6 { public static void main(String[] args) { JFrame frame = new JFrame("G"); frame.setLayout(new FlowLayout()); JLabel label = new JLabel("Hello"); frame.add(label); JRadioButton radio = new JRadioButton("Hello"); frame.add(radio); JCheckBox check = new JCheckBox("Hello"); frame.add(check); JTextField text = new JTextField("Hello"); frame.add(text); JButton button = new JButton("Hello"); frame.add(button); //Problemos..... frame.setSize (new Dimension (800,500)); frame.setVisible(true); } }
G7.java
import javax.swing.*; import java.awt.*; class G7 { public static void main(String[] args) { JFrame frame = new JFrame("G"); frame.setLayout(new GridLayout(10,5)); for(int i=0; i<50; i++) frame.add(new JButton("Hello")); frame.setSize (new Dimension (800,500)); frame.setVisible(true); } }
G8.java
import javax.swing.*; import java.awt.*; class G8 { public static void main(String[] args) { JFrame frame = new JFrame("G"); frame.setLayout(new GridLayout(2,1)); frame.add(new JLabel("Hello")); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(10,5)); for(int i=0; i<50; i++) panel.add(new JButton("Hello")); frame.add(panel); frame.setSize (new Dimension (800,500)); frame.setVisible(true); } }
G9.java
import javax.swing.*; import java.awt.*; class G9 { public static void main(String[] args) { JFrame frame = new JFrame("G"); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Hello"), BorderLayout.NORTH); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(10,5)); for(int i=0; i<50; i++) panel.add(new JButton("Hello")); frame.add(panel, BorderLayout.CENTER); frame.setSize (new Dimension (800,500)); frame.setVisible(true); } }
Genealogy.java
import java.util.Vector; class Person { String name; boolean male; boolean alive; Vector
siblings = new Vector
(); Vector
parents = new Vector
(); Vector
children = new Vector
(); Person spouse; Person(String name, boolean male, boolean alive) { this.name = name; this.male = male; this.alive = alive; } public String toString() { return this.name + " " + this.male + " " + this.alive; } Vector
getGrandParents() { Vector
grand = new Vector
(); for(int i=0; i
p = this.parents.get(i).parents; for(int j=0; i
Gui.java
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Gui implements ActionListener { JFrame w; JTextField tf; JLabel jl; Gui() { w = new JFrame(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FlowLayout fl = new FlowLayout(); w.setLayout(fl); tf = new JTextField(); tf.setColumns(30); JButton b = new JButton("Nespausk šio mygtuko"); b.addActionListener(this); jl = new JLabel("Čia bus rezultatas"); w.add(tf); w.add(b); w.add(jl); w.setSize(500, 200); w.setLocation(100, 200); w.setVisible(true); } public static void main(String[] args) { new Gui(); } @Override public void actionPerformed(ActionEvent arg0) { String s = tf.getText(); String sMas[] = s.split(" "); int m[] = new int[sMas.length]; for(int i=0; i
max) { max = m[i]; } } jl.setText(""+max); //w.setLocation((int)(Math.random()*500), (int)(Math.random()*500)); } }
H1.java
import java.awt.*; import javax.swing.*; class H1 extends JFrame{ public H1() { setSize(new Dimension(300, 200)); this.setLayout ( new BorderLayout() ); JTextField pi = new JTextField(""); this.add(pi, BorderLayout.NORTH); JPanel mygPanel = new JPanel(); mygPanel.setLayout( new GridLayout(4, 4)); String[] vard = { "1", "2", "3", "+", "4", "5", "6", "-", "7", "8", "9", "*", "0", "C", "=", "/"}; JButton[] mygtukai = new JButton[16]; for(int i=0; i<16; i++) { mygtukai[i] = new JButton(vard[i]); mygPanel.add(mygtukai[i]); } this.add(mygPanel, BorderLayout.CENTER); } public static void main(String[] args) { H1 frame = new H1(); frame.setVisible(true); } }
H2.java
import java.awt.*; import java.awt.event.*; import javax.swing.*; class H2 extends JFrame implements ActionListener { public H2() { setSize(new Dimension(300, 200)); this.setLayout ( new BorderLayout() ); JTextField pi = new JTextField(""); this.add(pi, BorderLayout.NORTH); JPanel mygPanel = new JPanel(); mygPanel.setLayout( new GridLayout(4, 4)); String[] vard = { "1", "2", "3", "+", "4", "5", "6", "-", "7", "8", "9", "*", "0", "C", "=", "/"}; JButton[] mygtukai = new JButton[16]; for(int i=0; i<16; i++) { mygtukai[i] = new JButton(vard[i]); mygtukai[i].addActionListener(this); mygPanel.add(mygtukai[i]); } this.add(mygPanel, BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { System.out.println( ((JButton)e.getSource()).getText() ); } public static void main(String[] args) { H2 frame = new H2(); frame.setVisible(true); } }
H3.java
import java.awt.*; import java.awt.event.*; import javax.swing.*; class H3 extends JFrame implements ActionListener { public H3() { setSize(new Dimension(300, 200)); this.setLayout ( new BorderLayout() ); JTextField pi = new JTextField(""); this.add(pi, BorderLayout.NORTH); JPanel mygPanel = new JPanel(); mygPanel.setLayout( new GridLayout(4, 4)); String[] vard = { "1", "2", "3", "+", "4", "5", "6", "-", "7", "8", "9", "*", "0", "C", "=", "/"}; JButton[] mygtukai = new JButton[16]; for(int i=0; i<16; i++) { mygtukai[i] = new JButton(vard[i]); mygtukai[i].addActionListener(this); mygPanel.add(mygtukai[i]); } this.add(mygPanel, BorderLayout.CENTER); this.addWindowListener ( new WindowAdapter() { public void windowClosing(WindowEvent e) { H3.this.windowClosed(); } } ); } protected void windowClosed() { System.exit(0); } public void actionPerformed(ActionEvent e) { System.out.println( ((JButton)e.getSource()).getText() ); } public static void main(String[] args) { H3 frame = new H3(); frame.setVisible(true); } }
H4.java
import java.awt.*; import java.awt.event.*; import javax.swing.*; class H4 extends JFrame implements ActionListener{ String skaicius=""; JTextField pi; public H4() { setSize(new Dimension(300, 200)); this.setLayout ( new BorderLayout() ); pi = new JTextField(""); this.add (pi, BorderLayout.NORTH); JPanel mygPanel = new JPanel(); mygPanel.setLayout( new GridLayout(4, 4)); JButton[] mygtukai = new JButton[16]; String[] vard = { "1", "2", "3", "+", "4", "5", "6", "-", "7", "8", "9", "*", "0", "C", "=", "/"}; for(int i=0; i<16; i++) { mygtukai[i] = new JButton(vard[i]); mygtukai[i].addActionListener(this); mygPanel.add(mygtukai[i]); } this.add(mygPanel, BorderLayout.CENTER); // Add window listener. this.addWindowListener ( new WindowAdapter() { public void windowClosing(WindowEvent e) { H4.this.windowClosed(); } } ); } /** * Shutdown procedure when run as an application. */ protected void windowClosed() { // Exit application. System.exit(0); } public void actionPerformed(ActionEvent e) { JButton b = (JButton)e.getSource(); String uzrasas = b.getText(); char simb = uzrasas.charAt(0); if(simb >= '0' && simb <= '9') skaicius += simb; else { System.out.println( skaicius ); } } public static void main(String[] args) { // Create application frame. H4 frame = new H4(); // Show frame. frame.setVisible(true); } }
Labirintas.java
package labirintas; public class Labirintas { static String[] lab = { "MMMMMMMMMMMMM", "M *M M", "M MMMM MMM M", " M M", "MMMMMMMMMMM M", "M M", "MMMMMMM MMMMM",}; static int[][] lb; static int ix, iy, z; public static void main(String[] args) { transfer(); forward(); backward(); print(); } static boolean test(int x, int y) { if (lb[x][y] == 0) { lb[x][y] = z + 1; if (x == 0 || y == 0 || x == lab.length - 1 || y == lab[x].length() - 1) { ix = x; iy = y; return true; } } return false; } static void transfer() { lb = new int[lab.length][lab[0].length()]; for (int i = 0; i < lab.length; i++) { for (int j = 0; j < lab[i].length(); j++) { if (lab[i].charAt(j) == 'M') { lb[i][j] = -1; } else if (lab[i].charAt(j) == ' ') { lb[i][j] = 0; } else { lb[i][j] = 1; } } } } static void forward() { boolean stop = false; for (z = 1; !stop; z++) { for (int i = 1; i < lab.length - 1; i++) { for (int j = 1; j < lab[i].length() - 1; j++) { if (lb[i][j] == z) { stop = stop || test(i - 1, j) || test(i, j - 1) || test(i + 1, j) || test(i, j + 1); } } } } } static void backward() { for (z--; z > 0; z--) { lb[ix][iy] = -2; if (ix > 0 && lb[ix - 1][iy] == z) { ix--; } else if (iy > 0 && lb[ix][iy - 1] == z) { iy--; } else if (ix < lab.length - 1 && lb[ix + 1][iy] == z) { ix++; } else if (iy < lab[ix].length() - 1 && lb[ix][iy + 1] == z) { iy++; } } } static void print() { for (int i = 0; i < lab.length; i++) { for (int j = 0; j < lab[i].length(); j++) { // System.out.print(lb[i][j] + " "); if (lb[i][j] == -1) { System.out.print("M"); } else if (lb[i][j] == -2) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } System.out.println(ix + " " + iy); } }
StackQueue.java
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class StackQueue implements ActionListener { JFrame w; JTextField tf; JLabel jl; StackQueue() { w = new JFrame(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FlowLayout fl = new FlowLayout(); w.setLayout(fl); tf = new JTextField(); tf.setColumns(30); JButton b = new JButton("Analyse"); b.addActionListener(this); jl = new JLabel("Result"); w.add(tf); w.add(b); w.add(jl); w.setSize(500, 200); w.setLocation(100, 200); w.setVisible(true); } public static void main(String[] args) { new StackQueue(); } @Override public void actionPerformed(ActionEvent arg0) { String s = tf.getText(); String sMas[] = s.split(" "); String result = ""; Stack stack = new Stack(sMas.length); Queue queue = new Queue(sMas.length); for(int command = 0; command < sMas.length; command++) { if(sMas[command].equals("push")) { command++; int v = Integer.parseInt(sMas[command]); stack.push(v); } if(sMas[command].equals("pop")) { result += stack.pop() + " "; } if(sMas[command].equals("en")) { command++; int v = Integer.parseInt(sMas[command]); queue.enqueue(v); } if(sMas[command].equals("de")) { result += queue.dequeue() + " "; } } jl.setText(result); } } class Stack { int[] stack; int pointer; Stack(int size) { stack = new int[size]; pointer = -1; } void push(int value) { pointer++; stack[pointer] = value; } int pop() { return stack[pointer--]; } } class Queue { int[] queue; int sPointer; int ePointer; Queue(int size) { queue = new int[size]; sPointer = 0; ePointer = -1; } void enqueue(int value) { ePointer++; queue[ePointer] = value; } int dequeue() { return queue[sPointer++]; } }
Star.java
import java.awt.*; import javax.swing.*; class Star extends JComponent { int NM = 16; int RADIUS = 100; public void setNM(int nm) { this.NM = nm; } public void repaint(){ this.getGraphics().clearRect(0,0,200,200); paint(this.getGraphics()); } public void paint(Graphics g) { for (double angle = 0; angle < Math.PI; angle = angle + 2 * Math.PI / NM ) { double x1 = Math.cos(angle) * RADIUS + RADIUS; double y1 = Math.sin(angle) * RADIUS + RADIUS; double x2 = Math.cos(angle + Math.PI) * RADIUS + RADIUS; double y2 = Math.sin(angle + Math.PI) * RADIUS + RADIUS; g.drawLine((int)x1, (int)y1, (int)x2, (int)y2); } } public Dimension getMinimumSize() { return new Dimension(2 * RADIUS, 2 * RADIUS); } public Dimension getPreferredSize() { return new Dimension(2 * RADIUS, 2 * RADIUS); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Star star = new Star(); frame.add(star); frame.pack(); frame.setVisible(true); } }
Star2.java
import java.awt.*; import javax.swing.*; class Star extends JComponent { int NM = 16; int RADIUS = 300; int SIZE = 800; public void setNM(int nm) { this.NM = nm; } public void repaint(){ this.getGraphics().clearRect(0,0,this.getSize().width, this.getSize().height); paint(this.getGraphics()); } public void paint(Graphics g) { int cx = this.getSize().width / 2; int cy = this.getSize().height / 2; double x1=0, y1=0, x2=0, y2=0; double delta = 2 * Math.PI / 5 * 3; double angle = 0; do { x2 = x1; y2 = y1; x1 = RADIUS * Math.cos(angle) + cx; y1 = RADIUS * Math.sin(angle) + cy; if (angle > 0) g.drawLine((int)x1, (int)y1, (int)x2, (int)y2); angle += delta; } while(angle <= 100 * Math.PI); } public Dimension getMinimumSize() { return new Dimension(SIZE, SIZE); } public Dimension getPreferredSize() { return new Dimension(SIZE, SIZE); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(900, 900); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); Star star = new Star(); frame.add(star, BorderLayout.CENTER); frame.setVisible(true); } }
Star3.java
import java.awt.*; import javax.swing.*; class Star extends JComponent { int NM = 16; int RADIUS = 300; int SIZE = 800; public void setNM(int nm) { this.NM = nm; } public void repaint(){ this.getGraphics().clearRect(0,0,this.getSize().width, this.getSize().height); paint(this.getGraphics()); } public double polarFunction(double phi) { return Math.sin(4*phi); } public void paint(Graphics g) { double delta = Math.PI / 200 + 0.5; int cx = this.getSize().width / 2; int cy = this.getSize().height / 2; double x1=0, y1=0, x2=0, y2=0; double angle = 0; do { x2 = x1; y2 = y1; x1 = polarFunction(angle) * RADIUS * Math.cos(angle) + cx; y1 = polarFunction(angle) * RADIUS * Math.sin(angle) + cy; g.setColor(new Color((int)x1%256,(int)x1%256,(int)y1%256)); if (angle > 0) g.drawLine((int)x1, (int)y1, (int)x2, (int)y2); angle += delta; } while(angle <= 100 * Math.PI); } public Dimension getMinimumSize() { return new Dimension(SIZE, SIZE); } public Dimension getPreferredSize() { return new Dimension(SIZE, SIZE); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(900, 900); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); Star star = new Star(); frame.add(star, BorderLayout.CENTER); frame.setVisible(true); } }
T1.java
import javax.swing.*; import java.awt.*; class Pav extends JFrame{ Pav() { this.setLayout(new BorderLayout()); this.setSize(200,200); ImageIcon img = new ImageIcon("G:/java/tutorial/2d/images/example-1dot2/images/boat.gif"); JButton m=new JButton(img); this.add(m, BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main (String args[]) { new Pav(); } }
T2.java
import javax.swing.*; import java.awt.*; import java.net.*; class Pav extends JFrame{ Pav() { this.setLayout(new BorderLayout()); this.setSize(200,200); ImageIcon img = null; try { img = new ImageIcon(new URL("http://g.delfi.lt/d/h/logo.gif")); } catch(MalformedURLException e){} JLabel m = new JLabel(img); this.add(m, BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public static void main (String args[]) { new Pav(); } }
T3.java
import java.awt.*; import javax.swing.*; import java.awt.event.*; class Kartuves extends JFrame implements ActionListener { JTextField zodis; JTextField raide; JLabel gyv; JButton pirmoZ, antroZ; String spejamasZodis; String jauAtspeta; int gyvybes = 9; Kartuves () { Container cp = this.getContentPane(); cp.setLayout(new GridLayout(3,2)); zodis = new JTextField(); cp.add(zodis); pirmoZ = new JButton("Nustatyti"); pirmoZ.addActionListener(this); cp.add(pirmoZ); raide = new JTextField(); cp.add(raide); antroZ = new JButton("Speti"); antroZ.addActionListener(this); antroZ.setEnabled(false); cp.add(antroZ); cp.add(new JLabel("Gyvybiu:")); gyv = new JLabel(""+gyvybes); cp.add(gyv); setSize(new Dimension(200,100)); } public void actionPerformed(ActionEvent e) { if (e.getSource() == pirmoZ) { paspaustasPirmas(); } else { paspaustasAntras(); } } void paspaustasPirmas(){ spejamasZodis=zodis.getText(); jauAtspeta=""; while(spejamasZodis.length()!=jauAtspeta.length()) jauAtspeta += "-"; zodis.setText(jauAtspeta); pirmoZ.setEnabled(false); antroZ.setEnabled(true); zodis.setEditable(false); } void paspaustasAntras(){ String spejimas = raide.getText(); if (spejimas.length()>0) { char simb = spejimas.charAt(0); int vieta = spejamasZodis.indexOf(simb); if( vieta == -1 ) { //nerado gyvybes--; gyv.setText(""+gyvybes); if (gyvybes==0) { antroZ.setEnabled(false); } } else { //rado 'vieta' vietoje StringBuffer sb = new StringBuffer(jauAtspeta); sb.setCharAt(vieta, simb); while ((vieta = spejamasZodis.indexOf(simb, vieta+1)) != -1) sb.setCharAt(vieta, simb); jauAtspeta = new String(sb); zodis.setText( jauAtspeta ); if (jauAtspeta.compareTo(spejamasZodis) == 0 ) { antroZ.setEnabled(false); JOptionPane.showMessageDialog(null, "Pasiseke", "Labai pasiseke", JOptionPane.ERROR_MESSAGE); } } } } public static void main(String arg[]) { Kartuves programa = new Kartuves(); programa.show(); } }
XADT.java
class Item { String info; Item next; Item(String info, Item next) { this.info=info; this.next=next; } Item(String info) { this(info, null); } } class Stack { Item head=null; void push(String info) { head = new Item(info, head); } String pop() { if(head != null) { String tmp = head.info; head = head.next; return tmp; } return null; } } class Queue { Item head=null; Item tail=null; void enqueue(String info) { } String dequeue() { } }