Friday, November 29, 2013
paint
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class paint{ public static void main(String[] args){ Icon iconB = new ImageIcon("blue.gif"); //the blue image icon Icon iconM = new ImageIcon("magenta.gif"); //magenta image icon Icon iconR = new ImageIcon("red.gif"); //red image icon Icon iconBl = new ImageIcon("black.gif"); //black image icon Icon iconG = new ImageIcon("green.gif"); //finally the green image icon //These will be the images for our colors. JFrame frame = new JFrame("Paint It"); //Creates a frame with a title of "Paint it" Container content = frame.getContentPane(); //Creates a new container content.setLayout(new BorderLayout()); //sets the layout final PadDraw drawPad = new PadDraw(); //creates a new padDraw, which is pretty much the paint program content.add(drawPad, BorderLayout.CENTER); //sets the padDraw in the center JPanel panel = new JPanel(); //creates a JPanel panel.setPreferredSize(new Dimension(32, 68)); panel.setMinimumSize(new Dimension(32, 68)); panel.setMaximumSize(new Dimension(32, 68)); //This sets the size of the panel JButton clearButton = new JButton("Clear"); //creates the clear button and sets the text as "Clear" clearButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.clear(); } }); //this is the clear button, which clears the screen. This pretty //much attaches an action listener to the button and when the //button is pressed it calls the clear() method JButton redButton = new JButton(iconR); //creates the red button and sets the icon we created for red redButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.red(); } }); //when pressed it will call the red() method. So on and so on =] JButton blackButton = new JButton(iconBl); //same thing except this is the black button blackButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.black(); } }); JButton magentaButton = new JButton(iconM); //magenta button magentaButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.magenta(); } }); JButton blueButton = new JButton(iconB); //blue button blueButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.blue(); } }); JButton greenButton = new JButton(iconG); //green button greenButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.green(); } }); blackButton.setPreferredSize(new Dimension(16, 16)); magentaButton.setPreferredSize(new Dimension(16, 16)); redButton.setPreferredSize(new Dimension(16, 16)); blueButton.setPreferredSize(new Dimension(16, 16)); greenButton.setPreferredSize(new Dimension(16,16)); //sets the sizes of the buttons panel.add(greenButton); panel.add(blueButton); panel.add(magentaButton); panel.add(blackButton); panel.add(redButton); panel.add(clearButton); //adds the buttons to the panel content.add(panel, BorderLayout.WEST); //sets the panel to the left frame.setSize(300, 300); //sets the size of the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //makes it so you can close frame.setVisible(true); //makes it so you can see it } } class PadDraw extends JComponent{ Image image; //this is gonna be your image that you draw on Graphics2D graphics2D; //this is what we'll be using to draw on int currentX, currentY, oldX, oldY; //these are gonna hold our mouse coordinates //Now for the constructors public PadDraw(){ setDoubleBuffered(false); addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ oldX = e.getX(); oldY = e.getY(); } }); //if the mouse is pressed it sets the oldX & oldY //coordinates as the mouses x & y coordinates addMouseMotionListener(new MouseMotionAdapter(){ public void mouseDragged(MouseEvent e){ currentX = e.getX(); currentY = e.getY(); if(graphics2D != null) graphics2D.drawLine(oldX, oldY, currentX, currentY); repaint(); oldX = currentX; oldY = currentY; } }); //while the mouse is dragged it sets currentX & currentY as the mouses x and y //then it draws a line at the coordinates //it repaints it and sets oldX and oldY as currentX and currentY } public void paintComponent(Graphics g){ if(image == null){ image = createImage(getSize().width, getSize().height); graphics2D = (Graphics2D)image.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); clear(); } g.drawImage(image, 0, 0, null); } //this is the painting bit //if it has nothing on it then //it creates an image the size of the window //sets the value of Graphics as the image //sets the rendering //runs the clear() method //then it draws the image public void clear(){ graphics2D.setPaint(Color.white); graphics2D.fillRect(0, 0, getSize().width, getSize().height); graphics2D.setPaint(Color.black); repaint(); } //this is the clear //it sets the colors as white //then it fills the window with white //thin it sets the color back to black public void red(){ graphics2D.setPaint(Color.red); repaint(); } //this is the red paint public void black(){ graphics2D.setPaint(Color.black); repaint(); } //black paint public void magenta(){ graphics2D.setPaint(Color.magenta); repaint(); } //magenta paint public void blue(){ graphics2D.setPaint(Color.blue); repaint(); } //blue paint public void green(){ graphics2D.setPaint(Color.green); repaint(); } //green paint } //good job, you've made your paint program =]
paint
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class paint{ public static void main(String[] args){ Icon iconB = new ImageIcon("blue.gif"); //the blue image icon Icon iconM = new ImageIcon("magenta.gif"); //magenta image icon Icon iconR = new ImageIcon("red.gif"); //red image icon Icon iconBl = new ImageIcon("black.gif"); //black image icon Icon iconG = new ImageIcon("green.gif"); //finally the green image icon //These will be the images for our colors. JFrame frame = new JFrame("Paint It"); //Creates a frame with a title of "Paint it" Container content = frame.getContentPane(); //Creates a new container content.setLayout(new BorderLayout()); //sets the layout final PadDraw drawPad = new PadDraw(); //creates a new padDraw, which is pretty much the paint program content.add(drawPad, BorderLayout.CENTER); //sets the padDraw in the center JPanel panel = new JPanel(); //creates a JPanel panel.setPreferredSize(new Dimension(32, 68)); panel.setMinimumSize(new Dimension(32, 68)); panel.setMaximumSize(new Dimension(32, 68)); //This sets the size of the panel JButton clearButton = new JButton("Clear"); //creates the clear button and sets the text as "Clear" clearButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.clear(); } }); //this is the clear button, which clears the screen. This pretty //much attaches an action listener to the button and when the //button is pressed it calls the clear() method JButton redButton = new JButton(iconR); //creates the red button and sets the icon we created for red redButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.red(); } }); //when pressed it will call the red() method. So on and so on =] JButton blackButton = new JButton(iconBl); //same thing except this is the black button blackButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.black(); } }); JButton magentaButton = new JButton(iconM); //magenta button magentaButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.magenta(); } }); JButton blueButton = new JButton(iconB); //blue button blueButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.blue(); } }); JButton greenButton = new JButton(iconG); //green button greenButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ drawPad.green(); } }); blackButton.setPreferredSize(new Dimension(16, 16)); magentaButton.setPreferredSize(new Dimension(16, 16)); redButton.setPreferredSize(new Dimension(16, 16)); blueButton.setPreferredSize(new Dimension(16, 16)); greenButton.setPreferredSize(new Dimension(16,16)); //sets the sizes of the buttons panel.add(greenButton); panel.add(blueButton); panel.add(magentaButton); panel.add(blackButton); panel.add(redButton); panel.add(clearButton); //adds the buttons to the panel content.add(panel, BorderLayout.WEST); //sets the panel to the left frame.setSize(300, 300); //sets the size of the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //makes it so you can close frame.setVisible(true); //makes it so you can see it } } class PadDraw extends JComponent{ Image image; //this is gonna be your image that you draw on Graphics2D graphics2D; //this is what we'll be using to draw on int currentX, currentY, oldX, oldY; //these are gonna hold our mouse coordinates //Now for the constructors public PadDraw(){ setDoubleBuffered(false); addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent e){ oldX = e.getX(); oldY = e.getY(); } }); //if the mouse is pressed it sets the oldX & oldY //coordinates as the mouses x & y coordinates addMouseMotionListener(new MouseMotionAdapter(){ public void mouseDragged(MouseEvent e){ currentX = e.getX(); currentY = e.getY(); if(graphics2D != null) graphics2D.drawLine(oldX, oldY, currentX, currentY); repaint(); oldX = currentX; oldY = currentY; } }); //while the mouse is dragged it sets currentX & currentY as the mouses x and y //then it draws a line at the coordinates //it repaints it and sets oldX and oldY as currentX and currentY } public void paintComponent(Graphics g){ if(image == null){ image = createImage(getSize().width, getSize().height); graphics2D = (Graphics2D)image.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); clear(); } g.drawImage(image, 0, 0, null); } //this is the painting bit //if it has nothing on it then //it creates an image the size of the window //sets the value of Graphics as the image //sets the rendering //runs the clear() method //then it draws the image public void clear(){ graphics2D.setPaint(Color.white); graphics2D.fillRect(0, 0, getSize().width, getSize().height); graphics2D.setPaint(Color.black); repaint(); } //this is the clear //it sets the colors as white //then it fills the window with white //thin it sets the color back to black public void red(){ graphics2D.setPaint(Color.red); repaint(); } //this is the red paint public void black(){ graphics2D.setPaint(Color.black); repaint(); } //black paint public void magenta(){ graphics2D.setPaint(Color.magenta); repaint(); } //magenta paint public void blue(){ graphics2D.setPaint(Color.blue); repaint(); } //blue paint public void green(){ graphics2D.setPaint(Color.green); repaint(); } //green paint } //good job, you've made your paint program =]
calculator
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- class Calculator extends JFrame {
- private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20);
- private JTextField textfield;
- private boolean number = true;
- private String equalOp = "=";
- private CalculatorOp op = new CalculatorOp();
- public Calculator() {
- textfield = new JTextField("", 12);
- textfield.setHorizontalAlignment(JTextField.RIGHT);
- textfield.setFont(BIGGER_FONT);
- ActionListener numberListener = new NumberListener();
- String buttonOrder = "1234567890 ";
- JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout(new GridLayout(4, 4, 4, 4));
- for (int i = 0; i < buttonOrder.length(); i++) {
- String key = buttonOrder.substring(i, i+1);
- if (key.equals(" ")) {
- buttonPanel.add(new JLabel(""));
- } else {
- JButton button = new JButton(key);
- button.addActionListener(numberListener);
- button.setFont(BIGGER_FONT);
- buttonPanel.add(button);
- }
- }
- ActionListener operatorListener = new OperatorListener();
- JPanel panel = new JPanel();
- panel.setLayout(new GridLayout(4, 4, 4, 4));
- String[] opOrder = {"+", "-", "*", "/","=","C","sin","cos","log"};
- for (int i = 0; i < opOrder.length; i++) {
- JButton button = new JButton(opOrder[i]);
- button.addActionListener(operatorListener);
- button.setFont(BIGGER_FONT);
- panel.add(button);
- }
- JPanel pan = new JPanel();
- pan.setLayout(new BorderLayout(4, 4));
- pan.add(textfield, BorderLayout.NORTH );
- pan.add(buttonPanel , BorderLayout.CENTER);
- pan.add(panel , BorderLayout.EAST);
- this.setContentPane(pan);
- this.pack();
- this.setTitle("Calculator");
- this.setResizable(false);
- }
- private void action() {
- number = true;
- textfield.setText("");
- equalOp = "=";
- op.setTotal("");
- }
- class OperatorListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String displayText = textfield.getText();
- if (e.getActionCommand().equals("sin"))
- {
- textfield.setText("" + Math.sin(Double.valueOf(displayText).doubleValue()));
- }else
- if (e.getActionCommand().equals("cos"))
- {
- textfield.setText("" + Math.cos(Double.valueOf(displayText).doubleValue()));
- }
- else
- if (e.getActionCommand().equals("log"))
- {
- textfield.setText("" + Math.log(Double.valueOf(displayText).doubleValue()));
- }
- else if (e.getActionCommand().equals("C"))
- {
- textfield.setText("");
- }
- else
- {
- if (number)
- {
- action();
- textfield.setText("");
- }
- else
- {
- number = true;
- if (equalOp.equals("="))
- {
- op.setTotal(displayText);
- }else
- if (equalOp.equals("+"))
- {
- op.add(displayText);
- }
- else if (equalOp.equals("-"))
- {
- op.subtract(displayText);
- }
- else if (equalOp.equals("*"))
- {
- op.multiply(displayText);
- }
- else if (equalOp.equals("/"))
- {
- op.divide(displayText);
- }
- textfield.setText("" + op.getTotalString());
- equalOp = e.getActionCommand();
- }
- }
- }
- }
- class NumberListener implements ActionListener {
- public void actionPerformed(ActionEvent event) {
- String digit = event.getActionCommand();
- if (number) {
- textfield.setText(digit);
- number = false;
- } else {
- textfield.setText(textfield.getText() + digit);
- }
- }
- }
- public class CalculatorOp {
- private int total;
- public CalculatorOp() {
- total = 0;
- }
- public String getTotalString() {
- return ""+total;
- }
- public void setTotal(String n) {
- total = convertToNumber(n);
- }
- public void add(String n) {
- total += convertToNumber(n);
- }
- public void subtract(String n) {
- total -= convertToNumber(n);
- }
- public void multiply(String n) {
- total *= convertToNumber(n);
- }
- public void divide(String n) {
- total /= convertToNumber(n);
- }
- private int convertToNumber(String n) {
- return Integer.parseInt(n);
- }
- }
- }
- class SwingCalculator {
- public static void main(String[] args) {
- JFrame frame = new Calculator();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- }
Chest
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- public class ChessGameDemo extends JFrame implements MouseListener, MouseMotionListener {
- JLayeredPane layeredPane;
- JPanel chessBoard;
- JLabel chessPiece;
- int xAdjustment;
- int yAdjustment;
- public ChessGameDemo(){
- Dimension boardSize = new Dimension(600, 600);
- // Use a Layered Pane for this this application
- layeredPane = new JLayeredPane();
- getContentPane().add(layeredPane);
- layeredPane.setPreferredSize(boardSize);
- layeredPane.addMouseListener(this);
- layeredPane.addMouseMotionListener(this);
- //Add a chess board to the Layered Pane
- chessBoard = new JPanel();
- layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
- chessBoard.setLayout( new GridLayout(8, 8) );
- chessBoard.setPreferredSize( boardSize );
- chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);
- for (int i = 0; i < 64; i++) {
- JPanel square = new JPanel( new BorderLayout() );
- chessBoard.add( square );
- int row = (i / 8) % 2;
- if (row == 0)
- square.setBackground( i % 2 == 0 ? Color.blue : Color.white );
- else
- square.setBackground( i % 2 == 0 ? Color.white : Color.blue );
- }
- //Add a few pieces to the board
- JLabel piece = new JLabel( new ImageIcon("/home/vinod/amarexamples/chess.jpg") );
- JPanel panel = (JPanel)chessBoard.getComponent(0);
- panel.add(piece);
- piece = new JLabel(new ImageIcon("/home/vinod/amarexamples/chess1.jpg"));
- panel = (JPanel)chessBoard.getComponent(15);
- panel.add(piece);
- piece = new JLabel(new ImageIcon("/home/vinod/amarexamples/king.jpg"));
- panel = (JPanel)chessBoard.getComponent(16);
- panel.add(piece);
- piece = new JLabel(new ImageIcon("/home/vinod/amarexamples/camel.jpg"));
- panel = (JPanel)chessBoard.getComponent(20);
- panel.add(piece);
- }
- public void mousePressed(MouseEvent e){
- chessPiece = null;
- Component c = chessBoard.findComponentAt(e.getX(), e.getY());
- if (c instanceof JPanel)
- return;
- Point parentLocation = c.getParent().getLocation();
- xAdjustment = parentLocation.x - e.getX();
- yAdjustment = parentLocation.y - e.getY();
- chessPiece = (JLabel)c;
- chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
- chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
- layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
- }
- //Move the chess piece around
- public void mouseDragged(MouseEvent me) {
- if (chessPiece == null) return;
- chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
- }
- //Drop the chess piece back onto the chess board
- public void mouseReleased(MouseEvent e) {
- if(chessPiece == null) return;
- chessPiece.setVisible(false);
- Component c = chessBoard.findComponentAt(e.getX(), e.getY());
- if (c instanceof JLabel){
- Container parent = c.getParent();
- parent.remove(0);
- parent.add( chessPiece );
- }
- else {
- Container parent = (Container)c;
- parent.add( chessPiece );
- }
- chessPiece.setVisible(true);
- }
- public void mouseClicked(MouseEvent e) {
- }
- public void mouseMoved(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e){
- }
- public void mouseExited(MouseEvent e) {
- }
- public static void main(String[] args) {
- JFrame frame = new ChessGameDemo();
- frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE );
- frame.pack();
- frame.setResizable(true);
- frame.setLocationRelativeTo( null );
- frame.setVisible(true);
- }
- }
Message - Up
import java.*; import java.security.MessageDigest; public class pw_test { public static void main(String[] args) { // Original: String imei = System.getProperty("com.nokia.mid.imei"); String imei = "580179140553553"; // your IMEI StringBuffer buffer = new StringBuffer(imei); if(buffer.length() == 0) { System.exit(0); } buffer = buffer.reverse(); S40MD5Digest digest = new S40MD5Digest(); digest.reset(); try { digest.update(buffer.toString().getBytes("UTF-8")); } catch(Exception e) { e.printStackTrace(); } byte bytes[] = digest.digest(); int bytesLength = bytes.length; buffer = new StringBuffer(); for(int i = 0; i < bytesLength; i++) { int unsignedByte = bytes[i] + 128; buffer.append(Integer.toString(unsignedByte, 16)); } System.out.println(buffer.toString()); } } class S40MD5Digest // implements com.whatsapp.api.util.MessageDigest { public S40MD5Digest() { try { _md5 = MessageDigest.getInstance("md5"); } catch(Exception x) { } } public void reset() { _md5.reset(); } public void update(byte bytes[]) { _md5.update(bytes, 0, bytes.length); } public byte[] digest() { byte arr[] = new byte[128]; int res; try { res = _md5.digest(arr, 0, 128); } catch(Exception x) { return null; } byte resArr[] = new byte[res]; System.arraycopy(arr, 0, resArr, 0, res); return resArr; } MessageDigest _md5; }
ali
<!DOCTYPE html>
<html id="facebook" class="tinyViewport" lang="en">
<head> … </head>
<body class="fbIndex UIPage_LoggedOut gecko win Locale_en_US">
<div class="_li">
<div id="pagelet_bluebar" data-referrer="pagelet_bluebar">
<div id="blueBarHolder">
<div id="blueBar">
<div>
<div class="loggedout_menubar_container">
<div class="clearfix loggedout_menubar">
<a class="lfloat" title="Go to Facebook Home" href="/"> … </a>
<div class="menu_login_container rfloat">
<form id="login_form" onsubmit="return window.Event && Event.__inlineSubmit && Event.__inlineSubmit(this,event)" method="post" action="https://www.facebook.com/login.php?login_attempt=1">
<input type="hidden" autocomplete="off" value="AVqC31eo" name="lsd"></input>
<table cellspacing="0">
<tbody>
<tr> … </tr>
<tr>
<td>
<input id="email" class="inputtext" type="text" tabindex="1" value="" name="email"></input>
</td>
<td> … </td>
<td> … </td>
</tr>
<tr> … </tr>
</tbody>
</table>
<input id="u_0_k" type="hidden" value="-120" name="timezone" autocomplete="off"></input>
<input type="hidden" value="085550_G4H8" name="lgnrnd"></input>
<input id="lgnjs" type="hidden" value="1385744155" name="lgnjs"></input>
<input id="locale" type="hidden" value="en_US" name="locale" autocomplete="off"></input>
</form>
</div>
</div>
</div>
<div id="login_chooser_container" class="_4--d hidden_elem"> … </div>
</div>
</div>
</div>
</div>
<div id="globalContainer" class="uiContextualLayerParent"> … </div>
</div>
<script data-signature="1" type="text/javascript"> … </script>
<script> … </script>
<script> … </script>
<script> … </script>
<!--
BigPipe construction and first response
-->
<script> … </script>
<script> … </script>
<script> … </script>
</body>
</html>
Subscribe to:
Posts (Atom)