import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class NeoPaint extends JFrame {

  class MenuFileAL implements ActionListener{
    public void actionPerformed(ActionEvent ev){
      
    }
  }

  class MenuEditAL implements ActionListener{
    public void actionPerformed(ActionEvent ev){
      
    }
  }

  class RadioThickAL implements ActionListener{
    public void actionPerformed(ActionEvent ev){
      
    }
  }

  class RadioLineAL implements ActionListener{
    public void actionPerformed(ActionEvent ev){
      
    }
    
    public void focusLost(FocusEvent ev){
      
    }
  }

  class TextColorAL implements ActionListener{
    public void actionPerformed(ActionEvent ev){
      
    }
  }

    // メイン
  public static void main(String[] args){
    (new NeoPaint()).setVisible(true);
  }
  // メニューバー
  private JMenuBar menuBar;

  // ファイルメニューアイテムリスナ
  private MenuFileAL fileMenuItemListener;
  // ファイルメニュー
  private JMenu fileMenu;
  // 新規作成メニューアイテム
  private JMenuItem createMenuItem;
  // 開くメニューアイテム
  private JMenuItem openMenuItem;
  // 名前を付けて保存メニューアイテム
  private JMenuItem saveAsMenuItem;
  // 閉じるメニューアイテム
  private JMenuItem closeMenuItem;

  // 編集メニューアイテムリスナー
  private MenuEditAL editMenuItemListener;
  // 編集メニュー
  private JMenu editMenu;
  // 元に戻すメニューアイテム
  private JMenuItem undoMenuItem;
  // やり直しメニューアイテム
  private JMenuItem redoMenuItem;

  // グリッドパネル
  private JPanel gridPanel;

  // ストロークリスナ
  private RadioThickAL strokeListener;
  // ストロークパネル
  private JPanel strokePanel;
  // ストロークラジオボタングループ
  private ButtonGroup strokeButtonGroup;
  // 太い--ラジオボタン
  private JRadioButton thickStrokeRadioButton;
  // 中--ラジオボタン
  private JRadioButton middleStrokeRadioButton;
  // 細い--ラジオボタン
  private JRadioButton thinStrokeRadioButton;

  // カラーリスナー
  private TextColorAL colorListener;
  // カラーパネル
  private JPanel colorPanel;
  // 赤テキストフィールド
  private JTextField redColorTextField;
  // 緑テキストフィールド
  private JTextField greenColorTextField;
  // 青テキストフィールド
  private JTextField blueColorTextField;
  //色見本
  private JLabel colorSampleLabel;

  // ドローモードリスナ
  private RadioLineAL drawModeListener;
  // ドローモードパネル
  private JPanel drawModePanel;
  // ドローモードラジオボタングループ
  private ButtonGroup drawModeButtonGroup;
  // フリーハンド--ラジオボタン
  private JRadioButton freehandDrawModeRadioButton;
  // 2点指定--ラジオボタン
  private JRadioButton twoPointDrawModeRadioButton;

  public NeoPaint(){
    super("ネオペイント");

    gridPanel = new JPanel(new GridLayout(2,2));

    setSize(800,500);
    setLocation(100,30);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    menuBar = new JMenuBar();

    fileMenuItemListener = new MenuFileAL();
    fileMenu = new JMenu("ファイル");

    createMenuItem = new JMenuItem("新規作成");
    createMenuItem.addActionListener(fileMenuItemListener);
    fileMenu.add(createMenuItem);

    openMenuItem = new JMenuItem("開く");
    openMenuItem.addActionListener(fileMenuItemListener);
    fileMenu.add(openMenuItem);

    saveAsMenuItem = new JMenuItem("名前を付けて保存");
    saveAsMenuItem.addActionListener(fileMenuItemListener);
    fileMenu.add(saveAsMenuItem);

    closeMenuItem = new JMenuItem("閉じる");
    closeMenuItem.addActionListener(fileMenuItemListener);
    fileMenu.add(closeMenuItem);

    menuBar.add(fileMenu);

    editMenuItemListener = new MenuEditAL();
    editMenu = new JMenu("編集");

    undoMenuItem = new JMenuItem("元に戻す");
    undoMenuItem.addActionListener(editMenuItemListener);
    editMenu.add(undoMenuItem);

    redoMenuItem = new JMenuItem("やり直し");
    redoMenuItem.addActionListener(editMenuItemListener);
    editMenu.add(redoMenuItem);

    menuBar.add(editMenu);

    add(menuBar, BorderLayout.NORTH);

    strokeListener = new RadioThickAL();
    strokePanel = new JPanel(new FlowLayout());

    strokePanel.add(new JLabel("太さ:"));

    strokeButtonGroup = new ButtonGroup();

    thickStrokeRadioButton = new JRadioButton("太");
    thickStrokeRadioButton.addActionListener(strokeListener);
    strokeButtonGroup.add(thickStrokeRadioButton);
    strokePanel.add(thickStrokeRadioButton);

    middleStrokeRadioButton = new JRadioButton("中", true);
    middleStrokeRadioButton.addActionListener(strokeListener);
    strokeButtonGroup.add(middleStrokeRadioButton);
    strokePanel.add(middleStrokeRadioButton);

    thinStrokeRadioButton = new JRadioButton("小");
    thinStrokeRadioButton.addActionListener(strokeListener);
    strokeButtonGroup.add(thinStrokeRadioButton);
    strokePanel.add(thinStrokeRadioButton);

    gridPanel.add(strokePanel);

    colorListener = new TextColorAL();
    colorPanel = new JPanel(new FlowLayout());

    Dimension dim = new Dimension(40, 25);
    colorPanel.add(new JLabel("色"));
    colorPanel.add(new JLabel("R:"));

    redColorTextField = new JTextField("255");
    redColorTextField.addActionListener(colorListener);
    redColorTextField.setPreferredSize(dim);
    colorPanel.add(redColorTextField);

    colorPanel.add(new JLabel("G:"));

    greenColorTextField = new JTextField("00");
    greenColorTextField.addActionListener(colorListener);
    greenColorTextField.setPreferredSize(dim);
    colorPanel.add(greenColorTextField);

    colorPanel.add(new JLabel("B:"));

    blueColorTextField = new JTextField("000");
    blueColorTextField.addActionListener(colorListener);
    blueColorTextField.setPreferredSize(dim);
    colorPanel.add(blueColorTextField);

    gridPanel.add(colorPanel);

    drawModeListener = new RadioLineAL();
    drawModePanel = new JPanel(new FlowLayout());

    drawModePanel.add(new JLabel("線描画法:"));
    drawModeButtonGroup = new ButtonGroup();

    freehandDrawModeRadioButton = new JRadioButton("フリーハンド", true);
    freehandDrawModeRadioButton.addActionListener(drawModeListener);
    drawModeButtonGroup.add(freehandDrawModeRadioButton);
    drawModePanel.add(freehandDrawModeRadioButton);

    twoPointDrawModeRadioButton = new JRadioButton("2点指定");
    twoPointDrawModeRadioButton.addActionListener(drawModeListener);
    drawModeButtonGroup.add(twoPointDrawModeRadioButton);
    drawModePanel.add(twoPointDrawModeRadioButton);

    gridPanel.add(drawModePanel);

    colorSampleLabel = new JLabel();
    gridPanel.add(colorSampleLabel);
    setColorSampleLabelColor();
    colorSampleLabel.setOpaque(true);

    menuBar.add(gridPanel);
  }

  private void setColorSampleLabelColor(){
    if(!isRegularColorNumber(redColorTextField)
    || !isRegularColorNumber(greenColorTextField)
    || !isRegularColorNumber(blueColorTextField)){
      colorSampleLabel.setForeground(new Color(255, 255, 255));
      colorSampleLabel.setText("RGBは各々000~255の値を指定してください");
      redColorTextField.setText("000");
      greenColorTextField.setText("000");
      blueColorTextField.setText("000");
    }else{
      colorSampleLabel.setText("");
    }

    colorSampleLabel.setBackground(new Color
      (
        Integer.parseInt(redColorTextField.getText()),
        Integer.parseInt(greenColorTextField.getText()),
        Integer.parseInt(blueColorTextField.getText())
      )
    );
  }

  private boolean isRegularColorNumber(JTextField jt){
    return jt.getText().matches("^([01][0-9][0-9]|2[0-4][0-9]|25[0-5])$");
  }
}
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;
 
public class HW20141216 {
  static String strCurrentLong = "";
  static long startLong = 0;
  static long currentLong = 0;
  static String OPRATOR_PLUS = "*";
  static TreeSet<Long> primeSet = new TreeSet<Long>();
  static boolean isToBeChecked = false;
  static String stringPrimeFact = "";
  static BufferedReader br = null;
  
  /*定数*/
  static final int MAX_DIGIT = 15;
  static final String START_COMMENT = "整数を入力してください。";
  static final String WARN_COMMENT = "2以上の整数を入力してください。";
  
  public static void main (String[] args) throws IOException, NumberFormatException {
    primeSet.add(new Long (2));
    try {
      br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println(START_COMMENT);
      readLineAndLongConvert();
      while (!(currentLong >=2)) {
        System.out.println(WARN_COMMENT);
        readLineAndLongConvert();
      }
      startLong = currentLong;
      long workLong = 2;
      makePrimeFactorization (workLong, currentLong);
    } catch (IOException iEx) {
      System.out.println(iEx.toString());
    } catch (NumberFormatException nEx) {
      System.out.println(nEx.toString());
    } finally {
      if (br != null) {
        br.close();
      }
      
    }
  }

  private static void makePrimeFactorization (long workLong, long currentLong) {
    while (currentLong !=1) {
      if(isToBeChecked(workLong) && currentLong % workLong == 0) {
        currentLong /= workLong;
        stringPrimeFact += workLong + OPRATOR_PLUS;
      } else {
        workLong = workLong > 2 ? workLong + 2 : workLong + 1;
      }
    }
    if (stringPrimeFact.length() > 0) {
      stringPrimeFact = stringPrimeFact.substring(0, stringPrimeFact.length() - 1);
      System.out.println(startLong + " = " + stringPrimeFact);
    }
  }

  private static void readLineAndLongConvert() throws IOException, NumberFormatException{
    strCurrentLong = br.readLine();
    currentLong = Long.parseLong(strCurrentLong);
  }

  private static boolean isToBeChecked (long workLong) {
    if(primeSet.contains(new Long(workLong))){
      return true;
    }
    for (long j :primeSet) {
      if(workLong % j == 0) {
        return false; 
      }else if (workLong % j != 0 && (double)j >= (double)Math.sqrt(workLong)){
        primeSet.add(new Long(workLong));
        return true;
      }
    }
    primeSet.add(new Long(workLong));
    return true;
  }
}

HW20150106

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class HW20150106 extends Applet implements MouseListener,MouseMotionListener {

  ArrayList<Point> points = new ArrayList<Point>();
  Point currentPoint;

  public void init(){
    addMouseListener(this);
    addMouseMotionListener(this);
  }

  public void paint(Graphics g){
    g.setColor(Color.red);
    Point prevPoint;
    if(points.isEmpty()){
      return;
    } else {
      prevPoint = points.get(0);
    }
    for (Point point : points) {
      g.drawLine(point.x, point.y, prevPoint.x, prevPoint.y);
      prevPoint = point;
    }
  }

  // マウスリスナー
  public void mousePressed(MouseEvent ev){
    System.out.println("mouse pressed");
  }
  public void mouseReleased(MouseEvent ev){
    System.out.println("mouse released");
  }
  public void mouseClicked(MouseEvent ev){
    currentPoint = new Point(ev.getX(), ev.getY());
    points.add(currentPoint);
    repaint();
    System.out.println("mouse clicked");
  }
  public void mouseEntered(MouseEvent ev){
    System.out.println("mouse entered");
    setBackground(Color.white);
  }
  public void mouseExited(MouseEvent ev){
    System.out.println("mouse exited");
    setBackground(Color.black);
  }
  public void mouseDragged(MouseEvent ev){
    if(currentPoint == null){
      currentPoint = new Point(ev.getX(), ev.getY());
    }
    int deltaX = ev.getX() - currentPoint.x;
    int deltaY = ev.getY() - currentPoint.y;
    for (Point point : points) {
      point.translate(deltaX, deltaY);
    }
    repaint();
  }
  public void mouseMoved(MouseEvent ev){
  }
}

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS