Суббота, 2025-02-08, 00:19:01
Главная Регистрация RSS
Приветствую Вас, Гость
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Урок 12.10 Примеры
j_todeskyДата: Четверг, 2011-10-13, 00:13:15 | Сообщение # 1
Рядовой
Группа: Проверенные
Сообщений: 18
Репутация: 1
Статус: Offline
тот, который назывался Interface

Code
public class Main {
   public static void main(String[] args) {
    shape circleshape=new circle();
    circleshape.Draw();
   }
}

interface shape
{
   public   String baseclass="shape";
   public void Draw();
}

class circle implements shape
{
   public void Draw() {
    System.out.println("Drawing Circle here");
   }

}

это jStopWatch
Добавлено (2011-10-13, 00:09:00)
---------------------------------------------
Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class jStopWatch implements ActionListener {
   JLabel jlab;
   long timeStart; // msec

   jStopWatch() {
    JFrame jfrm = new JFrame("stopwatch sample");
    jfrm.getContentPane().setLayout(new FlowLayout());
    jfrm.setSize(230, 90);
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton jbtnStart = new JButton("Start");
    JButton jbtnStop = new JButton("Stop");

    jbtnStart.addActionListener(this);
    jbtnStop.addActionListener(this);

    jfrm.getContentPane().add(jbtnStart);
    jfrm.getContentPane().add(jbtnStop);

    jlab = new JLabel("Press Start to begin timing.");
    jfrm.getContentPane().add(jlab);
      
    jfrm.setVisible(true);
   }

   public void actionPerformed(ActionEvent ae)
   {
    Calendar calend = Calendar.getInstance(); // get sys time
    if(ae.getActionCommand().equals("Start"))
    {
     timeStart = calend.getTimeInMillis();
     jlab.setText("Stopwatch is running..");
    }
    else
     jlab.setText("Elapsed time is "   
       + (double)(calend.getTimeInMillis()-timeStart/1000) );
   }

   public static void main(String args[]) {
    SwingUtilities.invokeLater(new Runnable() {
     public void run() {
      new jStopWatch();
     }
    });
   }

}

Добавлено (2011-10-13, 00:13:15)
---------------------------------------------
ну и CelsiusConverter

Code
/* From http://java.sun.com/docs/books/tutorial/index.html */

// v 1.3

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

// This example demonstrates the use of JButton, JTextField and JLabel.
public class CelsiusConverter implements ActionListener {
  JFrame converterFrame;

  JPanel converterPanel;

  JTextField tempCelsius;

  JLabel celsiusLabel, fahrenheitLabel;

  JButton convertTemp;

  // Constructor
  public CelsiusConverter() {
   // Create the frame and container.
   converterFrame = new JFrame("Convert Celsius to Fahrenheit");
   converterPanel = new JPanel();
   converterPanel.setLayout(new GridLayout(2, 2));

   // Add the widgets.
   addWidgets();

   // Add the panel to the frame.
   converterFrame.getContentPane()
     .add(converterPanel, BorderLayout.CENTER);

   // Exit when the window is closed.
   converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   // Show the converter.
   converterFrame.pack();
   converterFrame.setVisible(true);
  }

  // Create and add the widgets for converter.
  private void addWidgets() {
   // Create widgets.
   tempCelsius = new JTextField(2);
   celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
   convertTemp = new JButton("Convert...");
   fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);

   // Listen to events from Convert button.
   convertTemp.addActionListener(this);

   // Add widgets to container.
   converterPanel.add(tempCelsius);
   converterPanel.add(celsiusLabel);
   converterPanel.add(convertTemp);
   converterPanel.add(fahrenheitLabel);

   celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
   fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

  }

  // Implementation of ActionListener interface.
  public void actionPerformed(ActionEvent event) {
   // Parse degrees Celsius as a double and convert to Fahrenheit.
   int tempFahr = (int) ((Double.parseDouble(tempCelsius.getText())) * 1.8 + 32);
   fahrenheitLabel.setText(tempFahr + " Fahrenheit");
  }

  // main method
  public static void main(String[] args) {
   // Set the look and feel.
   try {
    UIManager.setLookAndFeel(UIManager
      .getCrossPlatformLookAndFeelClassName());
   } catch (Exception e) {
   }

   CelsiusConverter converter = new CelsiusConverter();
  }

}


Сообщение отредактировал j_todesky - Четверг, 2011-10-13, 00:10:28
 
  • Страница 1 из 1
  • 1
Поиск: