1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #5955

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    //skipped
            b1 = new JButton("Disable middle button", leftButtonIcon);
            b1.setVerticalTextPosition(AbstractButton.CENTER);
            b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            b1.setMnemonic(KeyEvent.VK_D);
            b1.setActionCommand("disable");
            b1.addActionListener(this);
    
    }
    
     public void actionPerformed(ActionEvent e) {
            if ("disable".equals(e.getActionCommand())) {
                b2.setEnabled(false);
                b1.setEnabled(false);
                b3.setEnabled(true);
            } else {
                b2.setEnabled(true);
                b1.setEnabled(true);
                b3.setEnabled(false);
            }

    из мануала на oracle.com. Что действительно так нужно обрабатывать события?

    KoirN, 11 Марта 2011

    Комментарии (4)
  3. Java / Говнокод #5885

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    public void run() {
    		try {
                        System.out.println("START QUOTE RECEIVER SERVER SOCKET..............");
                        try
                        {
                            Thread.sleep(5000);
                        }
                        catch (Exception ex) {}
                        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
    			ServerSocket serverSocket = new ServerSocket(port);
    			while (!isInterrupted()) {
    				new RemoteDataReceiver(serverSocket.accept());
    			}
    			serverSocket.close();
    		} catch (IOException e) 
                    {
                        e.printStackTrace();
    		}
    	}

    Русская синхронизация. Бессмысленная и беспощадная...

    papuas_guinea, 04 Марта 2011

    Комментарии (1)
  4. Java / Говнокод #5731

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    String DataStr = null;
    try {
        DataStr = new String(Data.toByteArray(), "UTF-8");
    } catch (Exception e) {
    }
    DataStr = DataStr.substring(1);

    Обработка ошибок, чо

    zeac, 20 Февраля 2011

    Комментарии (3)
  5. Java / Говнокод #5427

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @Ignore
    @Test
     public void testFetchDeviceList() throws Exception {
            //Assert.assertTrue(true);
    }

    Юнит тестирование :)

    artureg, 28 Января 2011

    Комментарии (8)
  6. Java / Говнокод #5298

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    class Scribble extends Component implements ActionListener {
    	
        protected Frame f;
        protected int w,h;
        
        public Scribble(Frame f, int w, int h){		
    	this.f = f;
    	this.w = w;
            this.h = h;
        }   
        @Override
        public Dimension getPreferredSize(){
    	return new Dimension(w,h);
        }	
        public void actionPerformed(ActionEvent event){		
        	String s = event.getActionCommand();
        	if(s.equals("Красный")) 
        	  Miner.currColor = Color.red;
        	else if(s.equals("Зелёный")) 
        	  Miner.currColor = Color.green;
        	else if(s.equals("Синий")) 
        	  Miner.currColor = Color.blue;
        	else if(s.equals("Серый")) 
        	  Miner.currColor = Color.gray;
        }
    }

    C меню выбора цвета полный провал
    dwinner - заслуженное звание java-быдло 2005!

    dwinner, 16 Января 2011

    Комментарии (4)
  7. Java / Говнокод #5297

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    public void Mina(int x, int y){
            Dimension d = this.getSize();
    	int dx = d.width/(MC+2);
    	int dy = d.height/(MR+2);
    	Graphics g = getGraphics();
            Graphics2D gr = (Graphics2D)g;
            GradientPaint gp = new GradientPaint(x, y, Color.white, x+dx, y+dy, Color.black, true);
            gr.setPaint(gp);
            gr.fill(new Ellipse2D.Double(x,y,dx,dy));
    	g.setColor(Color.black);
    	g.drawLine(x-1,y-1,x-1,y+dy);
    	g.drawLine(x-1,y-1,x+dx,y-1);
    	g.drawLine(x-1+dx,y-1,x-1+dx,y+dy);
    	g.drawLine(x-1,y-1+dy,x-1+dx,y-1+dy);
    	g.setColor(Miner.currColor);
    }

    Создаем рисунок программно! Градиентный шарик для Java - быстро ли?!

    dwinner, 16 Января 2011

    Комментарии (12)
  8. Java / Говнокод #4792

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for (int j = 0; j < fieldsToRemove.size(); j++) {
    	if (fieldsToDelete.getField(j).getKind().equals("GroupField")) {
    		resFieldContr.remove(j--);
    	}
    }

    собственно цикл.
    нашел в рабочем проекте

    tas, 30 Ноября 2010

    Комментарии (21)
  9. Java / Говнокод #4741

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Setted bit
    	private static final int TRUE_BIT = 1;
    
    ...
    	public static final int LAST_PARAGRAPH = 0x01;
    	public static final int FIRST_PARAGRAPH = 0x02;
    ...
    	
    	if (TRUE_BIT == (paragraphFlag & ParagraphProperties.FIRST_PARAGRAPH) >>> 1) {

    mlg7, 24 Ноября 2010

    Комментарии (5)
  10. Java / Говнокод #3918

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    public static void setSQLSafeFormat(JFormattedTextField ftf){
        DefaultFormatter sqlSafeFormatter = new DefaultFormatter(){
            @Override
            public Object stringToValue(String string) throws ParseException {
                string = string.replaceAll("\'", "");
                return super.stringToValue(string);
            }
            @Override
            public String valueToString(Object value) throws ParseException {
                 String result = super.valueToString(value);
                 return result.replaceFirst("\'", "");
            }
        };
        sqlSafeFormatter.setOverwriteMode(false);
        ftf.setFormatterFactory(new DefaultFormatterFactory(sqlSafeFormatter));
    }
    public static void setSQLSafeFilter(JTextField txt){
        DocumentFilter dc = new DocumentFilter(){
            @Override
            public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
                if(!string.contains("'"))
                super.insertString(fb, offset, string, attr);
            }
            @Override
            public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
                if(!text.contains("'"))
                super.replace(fb, offset, length, text, attrs);
            }
        };
        AbstractDocument asb = (AbstractDocument)txt.getDocument();
        asb.setDocumentFilter(dc);
    }

    суровая борьба с sql injection

    borka, 09 Августа 2010

    Комментарии (2)
  11. Java / Говнокод #3495

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    public static boolean isPow(BigInteger n){
    				    
    	   boolean zusammengesetzt=false;
    	   BigInteger obereSchranke=n;
    	   BigInteger untereSchranke=BigInteger.ONE;
    	   BigInteger t;	
                   
    	   for(BigInteger i=BigInteger.ONE;(i.compareTo(new BigInteger(new Integer((n.bitLength())).toString())) < 0);i=i.add(BigInteger.ONE)){
    	      while( (obereSchranke.subtract(untereSchranke)).compareTo(BigInteger.ONE) > 0){
    		     t=((obereSchranke.add(untereSchranke)).divide(new BigInteger("2")));
    		     if((pow(t,i.add(BigInteger.ONE))).compareTo(n) == 0){
    		        UserInterface.ausgabeFeld.append("Abbruch Schritt 1: Eingegebene Zahl ist nicht prim, da ");
    			    UserInterface.ausgabeFeld.append("n = "+t+"^"+i.add(BigInteger.ONE)+"\n"+"\n"); 
    				UserInterface.ausgabeFeld.repaint();
    				return zusammengesetzt=true;
    			    } 
    		     if((pow(t,i.add(BigInteger.ONE))).compareTo(n) > 0)
    			    obereSchranke=t;
    		     if((pow(t,i.add(BigInteger.ONE))).compareTo(n) < 0)
    				untereSchranke=t;
    		  }  
           }    
    	   UserInterface.ausgabeFeld.append("Schritt 1: "+n+" ist keine echte Potenz!"+"\n");
    	   UserInterface.ausgabeFeld.repaint();
    	   return zusammengesetzt;  
    	}

    Проверка условия вида "n = a^b".
    Впечатляет условие цикла for и реализация арифметических операций (хотя, может, с BigInteger так и надо).

    WxD, 16 Июня 2010

    Комментарии (8)