elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 2 3 4 5 6 7 8 9 10 11 [12] 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ... 45
111  Programación / Java / Re: Duda con la librería BigInteger en: 13 Febrero 2016, 17:09 pm
leí esto, según hasta donde entendí sólo tienes que pasar un 1 como parámetro para que retorne true si es probable que el número sea primo y false si no es probable que lo sea, si el parámetro es -1 funciona de forma inversa.
112  Programación / Java / Re: expandir jframe? en: 13 Febrero 2016, 16:46 pm
Pues la forma más fácil que conozco es usando layout, te te dejo un ejemplo sacado de stackoverflow

Código
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.GridBagConstraints;
  6. import java.awt.GridBagLayout;
  7. import java.awt.TextField;
  8. import java.awt.event.MouseEvent;
  9. import java.awt.event.MouseListener;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12.  
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JFrame;
  15. import javax.swing.JPanel;
  16. import javax.swing.JScrollPane;
  17. import javax.swing.JTextPane;
  18. import javax.swing.SwingUtilities;
  19. import javax.swing.text.DefaultStyledDocument;
  20. import javax.swing.text.StyledDocument;
  21.  
  22. public class DraftGUI implements MouseListener {
  23.  
  24.    private static final String IMAGE_URL = "http://images.paramountbusinessjets.com/space/spaceshuttle.jpg";
  25.    private JPanel jpPack;
  26.    private JPanel jpCards;
  27.    private JPanel jpInfo;
  28.    private JPanel jpChat;
  29.    private TextField tf;
  30.    private StyledDocument doc;
  31.    private JTextPane tp;
  32.    private JScrollPane sp;
  33.  
  34.    @Override
  35.    public void mousePressed(MouseEvent e) {
  36.    }
  37.  
  38.    @Override
  39.    public void mouseReleased(MouseEvent e) {
  40.    }
  41.  
  42.    @Override
  43.    public void mouseEntered(MouseEvent e) {
  44.    }
  45.  
  46.    @Override
  47.    public void mouseExited(MouseEvent e) {
  48.    }
  49.  
  50.    @Override
  51.    public void mouseClicked(MouseEvent e) {
  52.    }
  53.  
  54.    public DraftGUI() throws MalformedURLException {
  55.  
  56.        final JFrame frame = new JFrame("Draft");
  57.        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58.        // set the content pane, we'll add everything to it and then add it to the frame
  59.        JPanel contentPane = new JPanel();
  60.        contentPane.setLayout(new GridBagLayout());
  61.  
  62.        // creates some panels with some default values for now
  63.        JPanel jpCards = new JPanel(new BorderLayout());
  64.        jpCards.setBackground(Color.BLUE);
  65.  
  66.        JPanel jpInfo = new JPanel();
  67.        jpInfo.setBackground(Color.GREEN);
  68.  
  69.        JPanel jpPack = new JPanel(new GridBagLayout());
  70.        jpPack.setBackground(Color.RED);
  71.  
  72.        // grab some info to make the JTextPane and make it scroll
  73.        tf = new TextField();
  74.        doc = new DefaultStyledDocument();
  75.        tp = new JTextPane(doc);
  76.        tp.setEditable(false);
  77.        sp = new JScrollPane(tp);
  78.  
  79.        // adding the quantities to the chat panel
  80.        JPanel jpChat = new JPanel();
  81.        jpChat.setLayout(new BorderLayout());
  82.        jpChat.add("North", tf);
  83.        jpChat.add("Center", sp);
  84.  
  85.        // a new GridBagConstraints used to set the properties/location of the panels
  86.        GridBagConstraints c = new GridBagConstraints();
  87.  
  88.        // adding some panels to the content pane
  89.        // set it to start from the top left of the quadrant if it's too small
  90.        c.anchor = GridBagConstraints.FIRST_LINE_START;
  91.        c.fill = GridBagConstraints.BOTH; // set it to fill both vertically and horizontally
  92.        c.gridx = 0; // set it to quadrant x=0 and
  93.        c.gridy = 0; // set it to quadrant y=0
  94.        c.weightx = 0.7;
  95.        c.weighty = 0.3;
  96.        contentPane.add(jpCards, c);
  97.  
  98.        c.gridx = 1;
  99.        c.gridy = 0;
  100.        c.weightx = 0.3;
  101.        c.weighty = 0.3;
  102.        contentPane.add(jpInfo, c);
  103.  
  104.        c.gridx = 0;
  105.        c.gridy = 1;
  106.        c.weightx = 0.7;
  107.        c.weighty = 0.7;
  108.        contentPane.add(jpPack, c);
  109.  
  110.        c.gridx = 1;
  111.        c.gridy = 1;
  112.        c.weightx = 0.3;
  113.        c.weighty = 0.7;
  114.        contentPane.add(jpChat, c);
  115.  
  116.        // set some necessary values
  117.        frame.setContentPane(contentPane);
  118.        frame.setLocationByPlatform(true);
  119.  
  120.        // This code works for adding an Image
  121.        // need to learn how to specify a path not dependent on the specific users's machine
  122.        // this is not a high priority for now though
  123.        GridBagConstraints d = new GridBagConstraints();
  124.        d.weightx = 1.0;
  125.        d.weighty = 1.0;
  126.        d.fill = GridBagConstraints.BOTH;
  127.        d.gridx = 0;
  128.        d.gridy = 0;
  129.        ImageLabel imageLabel1 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
  130.        jpPack.add(imageLabel1, d);
  131.        ImageLabel imageLabel2 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
  132.        d.gridx++;
  133.        jpPack.add(imageLabel2, d);
  134.  
  135.        ImageLabel imageLabel3 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
  136.        d.gridy++;
  137.        jpPack.add(imageLabel3, d);
  138.  
  139.        imageLabel1.addMouseListener(this);
  140.        imageLabel2.addMouseListener(this);
  141.        imageLabel3.addMouseListener(this);
  142.        frame.pack();
  143.        // 223, 310 are the aspect values for a card image, width, height
  144.        // these need to be maintained as the GUI size changes
  145.            frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
  146.        frame.setVisible(true);
  147.    }
  148.  
  149.    public static void main(String[] args) {
  150.        SwingUtilities.invokeLater(new Runnable() {
  151.            @Override
  152.            public void run() {
  153.                try {
  154.                    new DraftGUI();
  155.                } catch (MalformedURLException e) {
  156.                    e.printStackTrace();
  157.                }
  158.            }
  159.        });
  160.    }
  161.  
  162.    public static class ImageLabel extends JPanel {
  163.        private static int counter = 1;
  164.        private ImageIcon icon;
  165.        private int id = counter++;
  166.  
  167.        public ImageLabel(ImageIcon icon) {
  168.            super();
  169.            setOpaque(false);
  170.            this.icon = icon;
  171.        }
  172.  
  173.        @Override
  174.        public Dimension getPreferredSize() {
  175.            return new Dimension(icon.getIconWidth(), icon.getIconHeight());
  176.        }
  177.  
  178.        @Override
  179.        protected void paintComponent(Graphics g) {
  180.            super.paintComponent(g);
  181.            double zoom = Math.min((double) getWidth() / icon.getIconWidth(), (double) getHeight() / icon.getIconHeight());
  182.            int width = (int) (zoom * icon.getIconWidth());
  183.            int height = (int) (zoom * icon.getIconHeight());
  184.            g.drawImage(icon.getImage(), (getWidth() - width) / 2, (getHeight() - height) / 2, width, height, this);
  185.            g.setFont(g.getFont().deriveFont(36.0f));
  186.            g.drawString(String.valueOf(id), getWidth() / 2, getHeight() / 2);
  187.        }
  188.    }
  189. }

la otra forma es que sepas el tamaño del Frame en tiempo de ejecución y dependiendo de ese tamaño cambiar el tamaño y la ubicación de todos los componentes, pero para eso hay que hacer muchos cálculos a mano.
113  Programación / Programación C/C++ / Re: Este es mi codigo y me marca [Error] Id returned 1 exit status en: 12 Febrero 2016, 16:59 pm
Una duda, ¿Estás usando el método main?
114  Programación / Java / Re: como pasar un dato a otra clase? en: 12 Febrero 2016, 15:05 pm
Conozco dos formas:
1. Crea un objeto de la clase que contiene los datos que vas a utilizar, en el lugar donde vayas a utilizar esos datos.

Por ejemplo, supongamos que tenemos una clase que calcula la suma de 2 números:

Código
  1. class Suma{
  2.    private int num1;
  3.    private int num2;
  4.    public Suma(int num1,int num2){
  5.        this.num1 = num1;
  6.        this.num2 = num2;  
  7.    }
  8.  
  9.    public int resultado(){
  10.        return num1 + num2;
  11.    }
  12. }

Ahora simplemente creamos un objeto de la clase suma:
Código
  1. Suma mySuma = new Suma(2,2); //2 + 2
  2. System.out.println(mySuma.resultado());//imprime 4

2. Haz que las variables que vayas a utilizar sean estáticos( usa la palabra reservada static), así no es necesario crear un objeto de la clase que contiene la variable, puedes acceder al valor de la variable poniendo NombreClase.NombreVariableEstática. al usar static en una variable haces que todas las instancias de una clase( los objetos ) tengan en mismo valor para esa variable, como si fuera una sola variable para todas las instancias.

Código
  1. class AlgunaClase{
  2.    public static int variable;
  3.  
  4. }

para acceder a la variable: AlgunaClase.variable
115  Programación / Java / Re: Me aparece un error extraño en una clase en: 12 Febrero 2016, 14:49 pm
De nada  ::)
116  Programación / Programación C/C++ / Re: ayuda con punteros a estructura en: 12 Febrero 2016, 04:49 am
usa el operador & para mostrar las direcciones de memoria:

Código
  1. int array[10] = {1, 2, 3, 4, 4, 7, 8, 9, 5, 4};
  2. int i;
  3. for(i =0; i<10;i++){
  4.    printf(" %p \n", &array[i]);
  5. }

Saludos.
117  Programación / Java / Re: Me aparece un error extraño en una clase en: 12 Febrero 2016, 00:47 am
El d es para variables de tipo int( no double como aparenta por la inicial de la palabra), si quieres imprimir variables de tipo double o float usa f

118  Foros Generales / Foro Libre / Re: ¿Que estudiaron? en: 10 Febrero 2016, 04:15 am
Bachillerato Técnico en Programación  ;-) aunque la verdad no aprendí nada mientras lo cursaba( tuve los peores maestros que se puedan imaginar), lo que sé lo aprendí en Internet  :laugh:
119  Programación / Java / Re: cerrar jinternalframe desde jframe en: 10 Febrero 2016, 04:13 am
Prueba con este código:

Código
  1. import javax.swing.JInternalFrame;
  2. import javax.swing.JDesktopPane;
  3. import javax.swing.JMenu;
  4. import javax.swing.JMenuItem;
  5. import javax.swing.JMenuBar;
  6. import javax.swing.JFrame;
  7. import java.awt.event.*;
  8. import java.awt.*;
  9. import java.beans.PropertyVetoException;
  10.  
  11. public class UCIChess extends JFrame {
  12.  
  13. JDesktopPane jdpDesktop;
  14. static int openFrameCount = 0;
  15. MyInternalFrame myInternalFrame;
  16.  
  17.        public UCIChess() {
  18. super("JInternalFrame Usage Demo");
  19. // Make the main window positioned as 50 pixels from each edge of the
  20. // screen.
  21. int inset = 50;
  22. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  23. setBounds(inset, inset, screenSize.width - inset * 2,
  24. screenSize.height - inset * 2);
  25. // Add a Window Exit Listener
  26. addWindowListener(new WindowAdapter() {
  27.  
  28. public void windowClosing(WindowEvent e) {
  29. System.exit(0);
  30. }
  31. });
  32.  
  33.                addKeyListener( new KeyAdapter(){
  34.                    public void keyPressed(KeyEvent e){
  35.                        if( e.getKeyCode() == KeyEvent.VK_ENTER ){
  36.                            try {
  37.                                myInternalFrame.setClosed(true);
  38.                                myInternalFrame.dispose();
  39.                            } catch (PropertyVetoException ex) {
  40.                                System.err.println("Closing Exception");
  41.                            }
  42.                        }
  43.                    }
  44.                });
  45. // Create and Set up the GUI.
  46. jdpDesktop = new JDesktopPane();
  47. // A specialized layered pane to be used with JInternalFrames
  48. createFrame(); // Create first window
  49. setContentPane(jdpDesktop);
  50. setJMenuBar(createMenuBar());
  51. // Make dragging faster by setting drag mode to Outline
  52. jdpDesktop.putClientProperty("JDesktopPane.dragMode", "outline");
  53. }
  54. protected JMenuBar createMenuBar() {
  55. JMenuBar menuBar = new JMenuBar();
  56. JMenu menu = new JMenu("Frame");
  57. menu.setMnemonic(KeyEvent.VK_N);
  58. JMenuItem menuItem = new JMenuItem("New IFrame");
  59. menuItem.setMnemonic(KeyEvent.VK_N);
  60. menuItem.addActionListener(new ActionListener() {
  61.  
  62. public void actionPerformed(ActionEvent e) {
  63. createFrame();
  64. }
  65. });
  66.  
  67. menu.add(menuItem);
  68. menuBar.add(menu);
  69. return menuBar;
  70. }
  71. protected void createFrame() {
  72. myInternalFrame = new MyInternalFrame();
  73. myInternalFrame.setVisible(true);
  74. // Every JInternalFrame must be added to content pane using JDesktopPane
  75. jdpDesktop.add(myInternalFrame);
  76. try {
  77. myInternalFrame.setSelected(true);
  78. } catch (java.beans.PropertyVetoException e) {
  79. }
  80. }
  81. public static void main(String[] args) {
  82. UCIChess frame = new UCIChess();
  83. frame.setVisible(true);
  84. }
  85. class MyInternalFrame extends JInternalFrame {
  86.  
  87. static final int xPosition = 30, yPosition = 30;
  88. public MyInternalFrame() {
  89. super("IFrame #" + (++openFrameCount), true, // resizable
  90. true, // closable
  91. true, // maximizable
  92. true);// iconifiable
  93. setSize(300, 300);
  94. // Set the window's location.
  95. setLocation(xPosition * openFrameCount, yPosition
  96. * openFrameCount);
  97. }
  98. }
  99. }

lo bajé de aqui y lo modifiqué tantito.
120  Programación / Java / Re: cerrar jinternalframe desde jframe en: 8 Febrero 2016, 23:06 pm
Hola, buscando un poco por internet encontré esto:

Código
  1. try {
  2.      jInternalFrame.setClosed(true);
  3.    } catch (PropertyVetoException ex) {
  4.        System.err.println("Closing Exception");
  5.    }

fuente.
Páginas: 1 2 3 4 5 6 7 8 9 10 11 [12] 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ... 45
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines