2017-05-14 4 views
0

JLabel Clock을 180도 회전시켜 거꾸로했기 때문에 일부 검색을 수행하고 Graphics2D를 사용하여 구현하려고했지만이를 얻을 수있는 방법을 찾을 수 없습니다 모든 것을 망쳐 놓지 않고 일하라. 어떤 도움을 주셔서 감사합니다.NetBeans를 사용하여 Java에서 Jlabel을 회전하십시오.

가장 큰 문제는 NetBeans를 사용하여 자동으로 jLabel을 만들었고 다른 예제에서 본 Graphics2D 코드 줄을 추가하려고 할 때 전체 블록이 작동을 멈추었 기 때문일 것으로 보입니다.

package time; 

import java.awt.Color; 
import java.awt.Toolkit; 
import java.util.Calendar; 
import java.util.GregorianCalendar; 
import java.text.DecimalFormat; 
import javax.swing.JTextField; 

/** 
* 
* @author beaty 
*/ 
public class Interface extends javax.swing.JFrame { 

    /** 
    * Creates new form Interface 
    */ 
    public Interface() { 

     //Sets background as black and makes it auto fullscreen, windowed 
     getContentPane().setBackground(Color.black); 


     initComponents(); 

     //make fullscreen 
     Toolkit tk = Toolkit.getDefaultToolkit(); 
     int xsize = (int) tk.getScreenSize().getWidth(); 
     int ysize = (int) tk.getScreenSize().getHeight(); 
     this.setSize(xsize, ysize); 


     //Thread generates the calendar and autoupdates 
     new Thread() 
     { 
      public void run() 
      { 
       while(true) 
       { 
        Calendar cal = new GregorianCalendar(); 
        DecimalFormat fmt = new DecimalFormat("00"); 


        int hour = cal.get(Calendar.HOUR); 
        int minute = cal.get(Calendar.MINUTE); 
        int second = cal.get(Calendar.SECOND); 
        int AM_PM = cal.get(Calendar.AM_PM); 

        String day_night = ""; 
        if(AM_PM ==1) 
        { 
         day_night = "PM"; 
        } 
        else 
        { 
         day_night = "AM"; 
        } 

        if(hour == 0) 
        { 
         hour = 12; 
        } 
        else 
        { 

        } 
        String time = hour + ":" + fmt.format(minute) + " " + day_night; 
        /*  Swap this trime string to add seconds 
          *String time = hour + ":" + fmt.format(minute) + ":" + fmt.format(second) + " " + day_night; 

        */ 

        Clock.setText(time); 
       } 
      } 
     }.start(); 

    } 

    /** 
    * This method is called from within the constructor to initialize the form. 
    * WARNING: Do NOT modify this code. The content of this method is always 
    * regenerated by the Form Editor. 
    */ 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">       
    private void initComponents() { 

     Clock = new javax.swing.JLabel(); 
     jButton1 = new javax.swing.JButton(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     setTitle("WHPL Clock"); 
     setAutoRequestFocus(false); 
     setBackground(new java.awt.Color(0, 0, 0)); 
     setUndecorated(true); 

     Clock.setBackground(new java.awt.Color(0, 0, 0)); 
     Clock.setFont(new java.awt.Font("DS-Digital", 0, 300)); // NOI18N 
     Clock.setForeground(new java.awt.Color(255, 255, 255)); 
     Clock.setText("7:45"); 
     Clock.setHorizontalAlignment(JTextField.CENTER); 

     jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/time/exit.png"))); // NOI18N 
     jButton1.setActionCommand("System.out(0);"); 
     jButton1.setBorder(new javax.swing.border.MatteBorder(new javax.swing.ImageIcon(getClass().getResource("/time/exit.png")))); // NOI18N 
     jButton1.setBorderPainted(false); 
     jButton1.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/time/exit_selected.png"))); // NOI18N 
     jButton1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton1ActionPerformed(evt); 
      } 
     }); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addGap(115, 115, 115) 
       .addComponent(Clock, javax.swing.GroupLayout.DEFAULT_SIZE, 1232, Short.MAX_VALUE)) 
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
       .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
       .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addGap(63, 63, 63) 
       .addComponent(Clock, javax.swing.GroupLayout.PREFERRED_SIZE, 221, Short.MAX_VALUE) 
       .addContainerGap()) 
     ); 

     getAccessibleContext().setAccessibleDescription(""); 

     pack(); 
    }// </editor-fold>       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {           
     // Button action to exit application 
     System.exit(0); 
    }           

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String args[]) { 
     /* Set the Nimbus look and feel */ 
     //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
     /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */ 
     try { 
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
       if ("Nimbus".equals(info.getName())) { 
        javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
     } catch (ClassNotFoundException ex) { 
      java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } 
     //</editor-fold> 

     /* Create and display the form */ 
     java.awt.EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       new Interface().setVisible(true); 
      } 
     }); 
    } 

    // Variables declaration - do not modify      
    private javax.swing.JLabel Clock; 
    private javax.swing.JButton jButton1; 
    // End of variables declaration     
} 

답변

0

나는 아래로

거꾸로 그래서 JLabel의 시계 180도 회전 위해 노력 해왔다? 누가 텍스트를 거꾸로 읽으려고합니까?

의 Graphics2D

사용하여 구현하려고? 그래픽을 사용하는 코드가 보이지 않습니다?

스윙은 실제로 구성 요소를 회전시키지 않습니다.

당신은 체크 아웃 할 수있다 :

  1. Text Icon를 - 그것은 텍스트처럼 보이는 아이콘을 만들 것입니다.

  2. Rotated Icon - 아이콘을 180도 회전 할 수 있습니다.

두 개의 아이콘이 함께 있고 아이콘을 회전하여 텍스트를 회전 할 수있는 구현이 있습니다.