Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Dimension;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.Timer;
- public class main {
- final static int circleCenterX = 350;
- final static int circleCenterY = 275;
- final static int radius = 275;
- static double initialTheta = Math.toRadians(90);
- static double theta = initialTheta;
- final static double thetaIncrement = -0.015;
- static JButton button = new JButton("Go");
- static JTextField textfield = new JTextField();
- static JLabel getname = new JLabel("Enter name:");
- static Timer timer;
- static boolean running = false;
- public static void doit(JPanel panel){
- panel.removeAll();
- panel.add(getname);
- getname.setBounds(50,21,getname.getPreferredSize().width,getname.getPreferredSize().height);
- panel.add(textfield);
- textfield.setBounds(getname.getLocation().x + getname.getPreferredSize().width + 5, 20, 144,20);
- panel.add(button);
- button.setBounds(textfield.getLocation().x + 149,20,50,20);
- panel.revalidate();
- panel.repaint();
- String textinfo = textfield.getText();
- if(textinfo.equals("")){
- System.out.println("enter a name man");
- }
- else{
- final String[] text = textinfo.split("");
- final int num = text.length;
- final JLabel[] letters = new JLabel[num];
- for(int i = 0; i < text.length; i ++){
- letters[i] = new JLabel();
- letters[i].setText(text[i]);
- letters[i].setBounds( //
- circleCenterX - (int) (Math.sin(theta) * radius), //
- circleCenterY - (int) (Math.cos(theta) * radius), //
- (int) letters[i].getPreferredSize().getWidth(), (int) letters[i].getPreferredSize().getHeight());
- theta -= thetaIncrement;
- }
- timer = new Timer(20001/601, new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- running = true;
- if(Math.round( Math.toDegrees(theta)) < 270){
- for(int i = 0; i < num; i ++){
- System.out.println(Math.toDegrees(theta));
- letters[i].setBounds( //
- circleCenterX - (int) (Math.sin(theta) * radius), //
- circleCenterY - (int) (Math.cos(theta) * radius), //
- (int) letters[i].getPreferredSize().getWidth(), (int) letters[i].getPreferredSize().getHeight());
- theta -= thetaIncrement;
- }
- }
- else if(Math.round(Math.toDegrees(theta)) >= 270 && Math.round(Math.toDegrees(theta)) <= 360){
- //((Timer)e.getSource()).setDelay(30001/601);
- for(int i = 0; i < num; i ++){
- letters[i].setLocation(letters[i].getLocation().x - 10, 275);
- if(letters[i].getLocation().x <= 35){
- ((Timer)e.getSource()).stop();
- theta = Math.toRadians(90);
- for(int x = 0; x < num; x++){
- if(x == 0){
- letters[x].setLocation(35 + (12 * (x)),275);
- }
- else{
- letters[x].setLocation(45 + (15 * (x)),275);
- }
- }
- running = false;
- }
- }
- }
- }
- });
- for(int i = 0; i < text.length; i ++){
- panel.add(letters[i]);
- }
- }
- }
- public static void main(String[] args) {
- final double initialTheta = Math.toRadians(90);
- // double initialTheta = Math.toRadians(0); // start north
- // double initialTheta = Math.toRadians(90); // start west
- // double initialTheta = Math.toRadians(180); // start south
- // double initialTheta = Math.toRadians(270); // start east
- JFrame frame = new JFrame();
- frame.setSize(new Dimension(800, 700));
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- final JPanel panel = new JPanel();
- panel.setLayout(null);
- frame.add(panel);
- panel.add(getname);
- getname.setBounds(50,21,getname.getPreferredSize().width,getname.getPreferredSize().height);
- panel.add(textfield);
- textfield.setBounds(getname.getLocation().x + getname.getPreferredSize().width + 5, 20, 144,20);
- panel.add(button);
- button.setBounds(textfield.getLocation().x + 149,20,50,20);
- /*Timer timer = new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- label.rotate();
- }
- });
- }
- }, 0, 1000l / 60l); // 60 frames per second */
- button.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- doit(panel);
- if(running){
- }
- else{
- if(textfield.getText().equals(""));
- else{
- timer.start();
- }
- }
- }
- });
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement