-
+1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
public static synchronized Tracker getDefaultTracker() {
Tracker tracker;
synchronized (MainApp.class) {
if (googleAnalTracker == null) {
analytics = GoogleAnalytics.getInstance(app());
GoogleAnalytics googleAnalytics = analytics;
int i = (DEBUG || STAGE) ? R.xml.app_tracker_debug : R.xml.app_tracker;
googleAnalTracker = googleAnalytics.newTracker(i);
googleAnalTracker.enableAutoActivityTracking(false);
}
tracker = googleAnalTracker;
}
return tracker;
}
Тайна гугла раскрыта
m0003r,
04 Февраля 2018
-
+1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
решение:
class Twofer {
String twofer(String name) {
if (name.equalsIgnoreCase("Alice")){
return "One for Alice, one for me.";
} else if (name.equalsIgnoreCase("Bob")) {
return "One for Bob, one for me.";
} else {
return "One for you, one for me.";
}
}
}
чтобы эти тесты проходили
задачка:
# Two Fer
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
```text
"One for X, one for me."
```
When X is a name or "you".
If the given name is "Alice", the result should be "One for Alice, one for me."
If no name is given, the result should be "One for you, one for me."
чувак решил не заморачиваться...
Lure Of Chaos,
03 Февраля 2018
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
public class App extends Application {
public static Context appContext;
@Override
public void onCreate() {
super.onCreate();
appContext = getApplicationContext();
}
}
Нужно больше контекста...
ausichenko,
02 Февраля 2018
-
−1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main implements ActionListener{
private JFrame frame;
private JTextArea area;
private JTextField fieldName, fieldAge, fieldWeight, fieldHeight, fieldSex;
private JButton button;
public static void main(String[] args) throws Exception{
Main main = new Main();
main.go();
}
public void go(){
frame = new JFrame();
JPanel panel = new JPanel();
JLabel labelName = new JLabel("Имя: ");
JLabel labelSex = new JLabel("Пол: ");
JLabel labelAge = new JLabel("Возраст: ");
JLabel labelWeight = new JLabel("Вес: ");
JLabel labelHeight = new JLabel("Рост: ");
fieldName = new JTextField(10);
fieldAge = new JTextField(10);
fieldWeight = new JTextField(10);
fieldHeight = new JTextField(10);
fieldSex = new JTextField(10);
area = new JTextArea(6, 73);
area.setWrapStyleWord(true);
area.setLineWrap(true);
button = new JButton("Расчитать");
button.addActionListener(this);
JScrollPane scroller = new JScrollPane(area);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(labelName);
panel.add(fieldName);
panel.add(labelSex);
panel.add(fieldSex);
panel.add(labelAge);
panel.add(fieldAge);
panel.add(labelWeight);
panel.add(fieldWeight);
panel.add(labelHeight);
panel.add(fieldHeight);
panel.add(area);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000, 200);
frame.setTitle("Расход калорий");
frame.setVisible(true);
}
public double bmrM(){
return 88.362 + (13.397 * Integer.parseInt(fieldWeight.getText())) + (6.25 * Integer.parseInt(fieldHeight.getText())) - (5 * Integer.parseInt(fieldAge.getText())) + 5;
}
public double bmrW(){
return 88.362 + (13.397 * Integer.parseInt(fieldWeight.getText())) + (6.25 * Integer.parseInt(fieldHeight.getText())) - (5 * Integer.parseInt(fieldAge.getText())) - 161;
}
public void actionPerformed(ActionEvent event){
if (fieldSex.getText().equals("Мужской") || fieldSex.getText().equals("мужской")){
area.setText(fieldName.getText() + ", ваш расход в спокойном режиме(без тренировочного процесса) составляет - " + bmrM() + " калорий.");
}else{
area.setText(fieldName.getText() + ", ваш расход в спокойном режиме(без тренировочного процесса) составляет - " + bmrW() + " калорий.");
}
}
}
Программа по расчету калорий!
Помогите улучшить код! КАК СОКРАТИТЬ???
babushkaAntona,
24 Декабря 2017
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.*;
public class Experiment5 implements ActionListener{
JFrame frame;
JList list;
JTextField text;
public static void main(String[] args) {
Experiment5 experiment5 = new Experiment5();
experiment5.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JButton button = new JButton("Click me");
button.addActionListener(this);
text = new JTextField();
String[] listEntries = {"Java", "C++", "Perl", "Python", "JavaScript", "PHP", "C#"};
list = new JList(listEntries);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new SelectionOne());
MyDrawPanel1 panel1 = new MyDrawPanel1();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.NORTH, text);
frame.getContentPane().add(BorderLayout.EAST, list);
frame.getContentPane().add(BorderLayout.CENTER, panel1);
frame.setSize(500, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
int ran = (int) (Math.random() * 255);
text.setText("New random - " + ran);
frame.repaint();
}
class SelectionOne implements ListSelectionListener {
public void valueChanged(ListSelectionEvent lse) {
if(!lse.getValueIsAdjusting()){
String selection = (String) list.getSelectedValue();
System.out.println(selection);
}
}
}
}
class MyDrawPanel1 extends JPanel{
public void paintComponent(Graphics g){
int one = (int)(Math.random() * 255);
int two = (int)(Math.random() * 255);
int three = (int)(Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(110, 10, 200, 200);
}
}
SWING!!! Jlist, JTextField, JPanel !!! КАК УЛУЧШИТЬ ЭТОТ ПОНОС???
babushkaAntona,
21 Декабря 2017
-
+2
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
public class RussianNumberUtils {
public static String getRussianNumberFormat(String number) {
StringBuilder numberBuilder = new StringBuilder();
try {
numberBuilder.append("+");
numberBuilder.append(number.charAt(0));
numberBuilder.append(" (");
numberBuilder.append(number.substring(1, 4));
numberBuilder.append(") ");
numberBuilder.append(number.substring(4, 7));
numberBuilder.append("-");
numberBuilder.append(number.substring(7, 9));
numberBuilder.append("-");
numberBuilder.append(number.substring(9, Math.max(number.length(), 11)));
return numberBuilder.toString();
} catch (Exception e) {}
return number;
}
}
Форматирование русского номера телефона
lukaville,
19 Декабря 2017
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ExperimentNew {
int x = 10;
int y = 10;
public static void main(String[] args) {
ExperimentNew experimentNew = new ExperimentNew();
experimentNew.go();
}
public void go(){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawPanel panel = new MyDrawPanel();
frame.getContentPane().add(panel);
frame.setSize(500,500);
frame.setVisible(true);
for (int i = 0; i < 450; i++){
if (i < 226) {
x++;
y++;
panel.repaint();
try {
Thread.sleep(50);
} catch (Exception ignored) {
}
}else{
x++;
y--;
panel.repaint();
try{
Thread.sleep(50);
}catch(Exception ignored){ }
}
}
}
class MyDrawPanel extends JPanel{
public void paintComponent(Graphics g){
g.setColor(Color.white);
g.fillRect(0,0, this.getWidth(), this.getHeight());
int one = (int) (Math.random() * 255);
int two = (int) (Math.random() * 255);
int three = (int) (Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(x, y, 20, 20);
}
}
}
Мигающая анимационная окружность! КАК СДЕЛАТЬ БОЛЕЕ КОМПАКТНО?
babushkaAntona,
17 Декабря 2017
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Gitis implements ActionListener{
JFrame frame;
public static void main(String[] args) {
Gitis gitis = new Gitis();
gitis.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Next Color");
button.addActionListener(this);
MyDrawPanel panel = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setSize(500, 500);
frame.setVisible(true);
frame.setTitle("Paint Oval");
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
class MyDrawPanel extends JPanel{
public void paintComponent(Graphics g){
g.fillRect(0, 0, this.getWidth(),this.getHeight());
int one = (int) (Math.random() * 255);
int two = (int) (Math.random() * 255);
int three = (int) (Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(40, 70 , 50, 50);
}
}
Смена цвета окружности по нажатию кнопки, Оцените код!
babushkaAntona,
16 Декабря 2017
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ServakPro;
/**
*
* @author bb
*/
import Debugger.NetDebugger;
import Debugger.NetDebuggingInter;
import Servak.Db.Experimental.SettingsBandit;
import java.io.*;
import java.net.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Server extends Object implements NetDebuggingInter {
static final int INITIALWORKERTHREADS = 20;// tune this!
static final int port = SettingsBandit.SERVER_PORT;
BlockingQueue<Socket> queue;
private ServerSocket ss;
private Thread internalThread;
private volatile boolean noStopRequested;
private NetDebugger netDebugger = new NetDebugger();
private void init() {
for (int i = 0; i < INITIALWORKERTHREADS; i++) {
new Thread(new MultiSessionTask(ss, queue)).start();
}
}
public Server(BlockingQueue<Socket> q) throws IOException {
ss = new ServerSocket(port);
noStopRequested = true;
this.queue = q;
this.init();
Runnable r = new Runnable() {
public void run() {
try {
runWorkFast();
} catch (Exception x) {
netDebugger.fireServerFaultEvent("SERVER: there is exception: ", x);
x.printStackTrace();
}
}
};
internalThread = new Thread(r);
internalThread.setName("My server Thread");
internalThread.start();
}
private void runWorkFast() {
for (;;) {
try {
Socket sock = ss.accept();
int thr = MultiSessionTask.waitCount();
if (thr > 0) {
queue.add(sock);
} else {
queue.add(sock);
new Thread(new DynamicMultiSessionTask(ss, queue)).start();
}
} catch (IOException exc) {
exc.printStackTrace();
}
if (ss.isClosed()) {
break; // for (;;)
}
} // catch
}
public synchronized void stopRequest() {
noStopRequested = false;
//internalThread.interrupt();
if (ss != null) {
try {
ss.close();
} catch (IOException x) {
// ignore
} finally {
ss = null;
}
}
}
public boolean isAlive() {
return internalThread.isAlive();
}
public static void main(String[] args) {
try {
BlockingQueue<Socket> bq = new ArrayBlockingQueue<>(40);
Server serv = new Server(bq);
} catch (IOException ex) {
Мега-сервер
https://wasm.in/threads/skorost-obrabotki-klientov-v-servere-na-dzhava.32423/#post-395115
SadKo,
15 Декабря 2017
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
import java.awt.event.*;
import javax.swing.*;
public class Experiment implements ActionListener{
JFrame frame;
JButton button;
public static void main(String[] args) {
Experiment experiment = new Experiment();
experiment.go();
}
public void go(){
frame = new JFrame();
button = new JButton("You is winner!");
button.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(400, 400);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
button.setText("You is loser!");
frame.setSize(700, 700);
}
}
GUI, Создание кнопки и ее изменение, а также изменение фрейма!!! ОЦЕНИТЕ КОД!
babushkaAntona,
14 Декабря 2017